Dany
Dany

Reputation: 2174

How to get packet sequentially using UDP protocol?

I am making application in c#. I am getting data on 24097 port continuously and i am recording that data as

UdpClient client = null;
 IPEndPoint ipep = null;
 client = new UdpClient(24097); 
 client.Client.ReceiveBufferSize = 25000;
 ipep = new IPEndPoint(IPAddress.Any,24097);
while(flag)
{
  byte[] data= = client.Receive(ref ipep);
}

But my problem is whatever packets i am getting are not in sequential order. I want to receive them in sequential manner. Please help me.Thanks in advance.

Upvotes: 0

Views: 2957

Answers (2)

Manjunath K Mayya
Manjunath K Mayya

Reputation: 1118

This link might help

http://www.codeproject.com/Articles/176722/Sending-messages-to-workstations-using-Socket-Prog/?display=PrintAll&fid=1618703&df=90&mpp=25&noise=3&prof=False&sort=Position&view=Quick

This sample has 2 parts. First one is the sender(in some pc) and the other one is the receiver(in client pc). Port mentioned in the sender should be same as the one in the receiver.

there is a text box and button(Send) button in the sender application. Run both the projects in the respective PCs.

On clicking Send button in the sender, data from the text box will be sent sequentially to the receiver.

Hope it is of some use. Thank you.

Upvotes: 0

Andrew Barber
Andrew Barber

Reputation: 40139

UDP does not guarantee anything about the order of the data you send. It is "fire and forget". If you need to keep the data in an ordered stream, you need to use TCP.

Otherwise, you would need to implement some sort of sequence ID in your datagrams themselves.

Upvotes: 6

Related Questions