Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java sockets not reading data

879202Jul 30 2011 — edited Aug 3 2011
Well, I've asked in a lot of places (stackoverflow, for example) and nobody could help me. I'm really desperate :S

I'm programming a server (java) - client (Android/Java) application. The server is a W7. All the communication goes well until one read in the client that freezes and stops reading data until I send it 2 times more.

The data not read is a byte array. I repeat that all the communication goes well until this point.

Here's the code that I use to send the data:
----------------------------
Long lLength = new Long(length);
byte [] bLength = this.longToBytes(lLength.longValue());
dos.write(bLength);
dos.flush();

dos.write(bLength);
dos.flush();

dos.write(bLength);
dos.flush();
----------------------------
This code transforms a long value into an 8 bytes array. As I said, when the first write is executed (and the client is waiting for data), the read is not done. It is not done until I execute the last write().

And here's the code to read it:
----------------------------
byte length[] = {0,0,0,0,0,0,0,0};
dis.read(length);

----------------------------
I've used Wireshark to sniff the traffic, and I can see that the byte array is send, and the client answers with an ACK, but the read is not done.

Here, http://www.megaupload.com/?d=PMKX2TWU , I've uploaded the capture that I've done with wireshark. Only the protocol data.


In the client and the server, the sockets are setup like this:
----------------------------
socket = new Socket(sIP, oiPort.intValue());
dos = new DataOutputStream(socket.getOutputStream());
dis = new DataInputStream(socket.getInputStream());
----------------------------
This is driving me mad... I don't know why, at one moment, the application stops reading the data, when I send it the same way as always.


I suppose that the problem may be in the input buffers of the client socket... But I don't know what to do or what to try...

Say that I've also test the server in a WXPSP3 and it still doesn't work.

Thank you very much,

Newlog.

Edited by: user1175854 on 30-jul-2011 15:51

Edited by: user1175854 on 30-jul-2011 15:53
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 31 2011
Added on Jul 30 2011
37 comments
4,370 views