tags:

views:

645

answers:

2

I have written a socket program where the client uses readUTF() and writeUTF() to communicate with the server while the server uses read and write() to communicate with client. Actually My server can read all the data coming from server. But as I am using write() in server side and readUTF() in client side.

So In this scenario My Client is unable to get all the data that is sent by the server If the data size is more only some portion of data is received.

Thanks Bapi

A: 

Note that readUTF and writeUTF use a modified form of UTF. I don't know what you're sending using read() and write() on the server, but you should ensure that there's compatibility between what the client expects and what the server expects.

I would make both client and server send/receive using the same method. I don't know if that's causing your problem, but it will save you some unrelated grief.

Brian Agnew
+1  A: 

Do not use readUTF and writeUTF in this scenario. Instead read and write byte arrays:

read(byte [] b)

Then convert the byte array to a String using the appropriate String constructor:

public String(byte[] bytes,
              String charsetName)

You should try-catch UnsupportedEncodingException exceptions.

kgiannakakis