java socket input reading troubles

  • Thread starter Mohamed Naoufel Ben Salah
  • Start date
M

Mohamed Naoufel Ben Salah

Hi,
I'm using java socket a client side,
i have a server that sends data
packets, I read, decode, .....

I have trouble getting all the data sent by the server,
what I receive is a sequence of packets 1,2,3 ...
I receive 1 then 2 and when I read the next it is number
4 or 5.

I have no exceptions !

how can it happen !!!

can a matter of size/buffering mechanism .... make me
avoid this ?

(the server is "solid", and the data is really sent)

thanks in advence.
 
D

Danny Woods

Mohamed Naoufel Ben Salah said:
I have trouble getting all the data sent by the server,
what I receive is a sequence of packets 1,2,3 ...
I receive 1 then 2 and when I read the next it is number
4 or 5.

The first question would have to be whether you're using a Socket or
DatagramSocket? If it's a DatagramSocket, then missing or out-of-order data
is just a fact of life: if you require reliable data transfer over UDP, you'll
need some additional protocol to detect missing data and re-request holes in
the packet stream (something that the server will have to support).

If it's a plain TCP-based java.net.Socket and you're receiving data out
of order, then something's seriously amiss, as the protocol itself
explicitly protects against this (failing rather than missing data or
delivering it unordered).

In any case, the Ethereal network analysis tool is invaluable for tracking
this kind of stuff down (http://www.ethereal.com). Provided the client
and the server are on different machines, you'll be able to tell exactly
which data is being sent to/from your box (it doesn't work with the loopback
address).

Failing that, posting some code might allow people to help more effectively.

Regards,

Danny.
 
S

Steve Horsley

Mohamed said:
Hi,
I'm using java socket a client side,
i have a server that sends data
packets, I read, decode, .....

I have trouble getting all the data sent by the server,
what I receive is a sequence of packets 1,2,3 ...
I receive 1 then 2 and when I read the next it is number
4 or 5.

I have no exceptions !

how can it happen !!!

can a matter of size/buffering mechanism .... make me
avoid this ?

(the server is "solid", and the data is really sent)

thanks in advence.

Without code I can't be sure, but I guess you are ignoring recieve
data yourself. Remember that read() does not necessarily read data in
the same size chunks as it is sent. Would your code know if two
messages arrived in a single read(byte[])? Hint: read(byte[]) returns
how many bytes were read.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top