Win a copy of Rust Web Development this week in the Other Languages forum!

Jeff Jones

Greenhorn
+ Follow
since May 10, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jeff Jones

Ryan,
Thank you for the reply and I had the server
print out the string in a sentence to make sure
it did look the same as the original string sent.
System.out.println("--->" + socketString + "<----");<br /> output:<br /> --->Hello<---
So, I know that there wasn't any data loss and
the string does not have any visible additions.
I am thinking that maybe the string is changed
from a particular format during the byte transition
and then when it is recast as a string on the
server side that it is no longer the same object.
If it were, then the hashCode() would be the same.
Just my guess, but I am not sure how to change
the string back to the way before it was before
I sent it through the UDP socket.
Jeff
I have a question about the Strings being
sent through a UDP socket and then having
a new hash code upon retrieval. For example,
I have a string "Hello" and I cast it as
bytes and send it in a Datagram to a server:
// Client does this
byte[] sendData = new byte[1024];
sendData = myString.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IP, port);
The server receives the packet and the string
is cast from the data received.
// Server does this
String socketString = new String(receivedPacket.getData());
The server has a Hashtable, so it looks up the string
"Hello" which is supposed to be in the Hashtable, but
it isn't there. Why is that? I then create another
String:
String regularString = "Hello";
and look it up in the Hashtable and it is there.
So I take the regular String and use the equal()
method to the string passed through the UDP socket
and they say they are not equal?
return(regularString.equal(socketString));
false
How do I make the string that came through the UDP
socket a regular normal string like it was before
it left my client?
Thanks
Jeff
[This message has been edited by Jeff Jones (edited May 10, 2001).]