K
korcs
Hi,
I was wondering about the right "safest" usage of the DataInput/
OutputStream functions write/readUTF.
If I communicate via Sockets and the Server sends a message in form of
a string, how can a make sure that at the time of reading the message,
I read the whole message and not only a stub of it.
So if The message is "Santa Claus has a present for you.", how can I
make sure, that as a Client I read the whole message and not only
"Santa Claus has a present"
The server writes the message like:
DataOutputStream os;
String message = "Santa Claus has a present for you"
os.writeUTF(message);
os.flush();
The client reads the message like:
DataInputStream is;
String message = is.readUTF();
Is it all the time correct, or should I use a method to make 100% sure
that I have read the whole message?
(A method could be:
Server side: send first the byte length of the message as a "short"
then the message itself;
Client side: read first the length with the method "readShort" and
then to read exactly as many bytes, as the message length is...)
Does somebody know the official solution for the problem?
Best, korcs
I was wondering about the right "safest" usage of the DataInput/
OutputStream functions write/readUTF.
If I communicate via Sockets and the Server sends a message in form of
a string, how can a make sure that at the time of reading the message,
I read the whole message and not only a stub of it.
So if The message is "Santa Claus has a present for you.", how can I
make sure, that as a Client I read the whole message and not only
"Santa Claus has a present"
The server writes the message like:
DataOutputStream os;
String message = "Santa Claus has a present for you"
os.writeUTF(message);
os.flush();
The client reads the message like:
DataInputStream is;
String message = is.readUTF();
Is it all the time correct, or should I use a method to make 100% sure
that I have read the whole message?
(A method could be:
Server side: send first the byte length of the message as a "short"
then the message itself;
Client side: read first the length with the method "readShort" and
then to read exactly as many bytes, as the message length is...)
Does somebody know the official solution for the problem?
Best, korcs