0
votes

Writing a client/server based on UDP using Java.

When the server constantly gets packets from the socket:

socket.receive(packet); 

And even though the client is sending multiple packets, say packet 1,2,3 and 4, the client can only get the packet 4. It makes no difference to resend all these packets or send them in the opposite sequence of 4,3,2 and 1. The client can only get the packet with larger sequence number, which is kind of magical. But what I actually want is to get all the 4 packets.

1
Post some code. How are you sending the data? Are you receiving the data in a separate thread? - Thorn
@Thorn:It is not in thread. The Sender part looks like: for(int i=0;i<10;i++){socket.send(packet[i]);} - CodeFarmer
I still need more code to help you. Post all the relevant code for sending and receiving UDP packets. - Thorn
@Thorn Please see my edited codes up there and thanks! - CodeFarmer
If it's solved, write the solution as an answer, and accept our asnwer - dantuch

1 Answers

1
votes

You are using the same underlying byte[] array 'dataBuf' for all the sent DatagramPackets, so they don't remain distinct during resend.