471,355 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,355 software developers and data experts.

udp buffer issue

I have some code that continually reads packets off of a udp port
where the incoming packets are 26 bytes in length.

CODE: byte[] recBytes = udpClient.Receive(ref ipEndPoint);

I have left the udp buffer length at the default 8192. After
approximately 320 packets have been read, packets are being missed,
almost like the buffer is full and is not queueing incoming packets
any longer. 320 lines * 26 bytes = ~ the size of the udp buffer. If
I increase the buffer size, the problem is delayed proportionally. Is
there some way that the buffer would back up where the Receive() calls
would not dequeue? (I am making some assumptions on how the udp queue
functions internally, so please forgive me if I have made the wrong
assumptions here.)

I have other code that uses the same logic and it does not experience
this issue, which is really strange to me.

Any help would be greatly appreciated.

Thanks,

Chris

Aug 6 '07 #1
3 3751
cm****@hotmail.com wrote:
I have some code that continually reads packets off of a udp port
where the incoming packets are 26 bytes in length.

[...]
Is
there some way that the buffer would back up where the Receive() calls
would not dequeue?
Not assuming you are actually calling Receive(), no. Receive() consumes
the received data.

You will need to post a concise-but-complete example of code that
reliably reproduces the problem. The single line of code you posted is
not anywhere close to properly representing what you're actually doing
in your code.

Note also that for networking code, "complete" means that you post both
sending and receiving code. For any example, "concise" means that you
reduce the code to the bare minimum required to reproduce the problem.

Pete
Aug 6 '07 #2
On Aug 6, 1:24 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
cmh...@hotmail.com wrote:
I have some code that continually reads packets off of a udp port
where the incoming packets are 26 bytes in length.
[...]
Is
there some way that the buffer would back up where the Receive() calls
would not dequeue?

Not assuming you are actually calling Receive(), no. Receive() consumes
the received data.

You will need to post a concise-but-complete example of code that
reliably reproduces the problem. The single line of code you posted is
not anywhere close to properly representing what you're actually doing
in your code.

Note also that for networking code, "complete" means that you post both
sending and receiving code. For any example, "concise" means that you
reduce the code to the bare minimum required to reproduce the problem.

Pete
>>>>>>>>>>>>>>>>>>>>>>
Hi Pete,

Line 334 is where the sequence number jumps (byte 21) from BE to FB.
I don't have the code that sends the packets...it's an embedded system
outside of my reach, but I have pasted some source code below for the
receiving portion of the code and the console output. The packets are
all 26 bytes long though. I can see them using Wireshark to verify
their content.

Thanks,

Chris

--------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;

namespace TestUDP
{
public partial class Form1 : Form
{
bool stopReading = false;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
UdpClient udpClient = new UdpClient(5002);
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any,
5002);

int lineCounter = 0;

while (!stopReading)
{
byte[] recBytes = udpClient.Receive(ref ipEndPoint);
foreach (byte b in recBytes)
Console.Write(b.ToString("X2") + @" ");
Console.WriteLine(@" Line:" + ++lineCounter);
Application.DoEvents();
}

udpClient.Close();
this.Close();

}

private void button2_Click(object sender, EventArgs e)
{
stopReading = true;
}
}
}

--------------------

CONSOLE OUTPUT --->

00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 4C 00 00 BC 58
00 00 00 Line:307
00 1A B8 00 00 36 00 85 D1 B0 00 02 04 00 85 D1 00 03 4C 00 00 BC 35
00 00 00 Line:308
00 1A B8 00 00 5A 00 85 D1 B0 00 05 04 00 85 D1 00 03 4C 00 00 BC 5A
00 00 00 Line:309
00 1A B8 00 00 52 00 85 D1 B0 00 04 04 00 85 D1 00 03 4C 00 00 BC 42
00 00 00 Line:310
00 1A B8 00 00 3A 00 85 D1 B0 00 03 04 00 85 D1 00 03 4C 00 00 BC 43
00 00 00 Line:311
00 1A B8 00 00 38 00 85 D1 B0 00 06 04 00 85 D1 00 03 4C 00 00 BC 3F
00 00 00 Line:312
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 4C 00 00 BC 4A
00 00 00 Line:313
00 1A B8 00 00 16 00 85 D1 B0 00 00 04 00 85 D1 00 03 4C 00 00 BC 52
00 00 00 Line:314
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 4C 00 00 BC 00
00 00 00 Line:315
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 4D 00 00 BD 58
00 00 00 Line:316
00 1A B8 00 00 36 00 85 D1 B0 00 02 04 00 85 D1 00 03 4D 00 00 BD 35
00 00 00 Line:317
00 1A B8 00 00 5A 00 85 D1 B0 00 05 04 00 85 D1 00 03 4D 00 00 BD 5A
00 00 00 Line:318
00 1A B8 00 00 16 00 85 D1 B0 00 00 04 00 85 D1 00 03 4D 00 00 BD 52
00 00 00 Line:319
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 4D 00 00 BD 4A
00 00 00 Line:320
00 1A B8 00 00 52 00 85 D1 B0 00 04 04 00 85 D1 00 03 4D 00 00 BD 42
00 00 00 Line:321
00 1A B8 00 00 3A 00 85 D1 B0 00 03 04 00 85 D1 00 03 4D 00 00 BD 43
00 00 00 Line:322
00 1A B8 00 00 38 00 85 D1 B0 00 06 04 00 85 D1 00 03 4D 00 00 BD 3F
00 00 00 Line:323
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 4D 00 00 BD 00
00 00 00 Line:324
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 4E 00 00 BE 58
00 00 00 Line:325
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 4E 00 00 BE 4A
00 00 00 Line:326
00 1A B8 00 00 36 00 85 D1 B0 00 02 04 00 85 D1 00 03 4E 00 00 BE 34
00 00 00 Line:327
00 1A B8 00 00 5A 00 85 D1 B0 00 05 04 00 85 D1 00 03 4E 00 00 BE 5A
00 00 00 Line:328
00 1A B8 00 00 16 00 85 D1 B0 00 00 04 00 85 D1 00 03 4E 00 00 BE 52
00 00 00 Line:329
00 1A B8 00 00 52 00 85 D1 B0 00 04 04 00 85 D1 00 03 4E 00 00 BE 42
00 00 00 Line:330
00 1A B8 00 00 3A 00 85 D1 B0 00 03 04 00 85 D1 00 03 4E 00 00 BE 43
00 00 00 Line:331
00 1A B8 00 00 38 00 85 D1 B0 00 06 04 00 85 D1 00 03 4E 00 00 BE 3F
00 00 00 Line:332
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 4E 00 00 BE 00
00 00 00 Line:333
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 8B 00 00 FB 57
00 00 00 Line:334
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 8B 00 00 FB 49
00 00 00 Line:335
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 8B 00 00 FB 00
00 00 00 Line:336
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 8C 00 00 FC 58
00 00 00 Line:337
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 8C 00 00 FC 49
00 00 00 Line:338
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 8D 00 00 FD 58
00 00 00 Line:339
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 8D 00 00 FD 4A
00 00 00 Line:340
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 8D 00 00 FD 00
00 00 00 Line:341
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 8E 00 00 FE 58
00 00 00 Line:342
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 8E 00 00 FE 4A
00 00 00 Line:343
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 8F 00 00 FF 58
00 00 00 Line:344
00 1A B8 00 00 5A 00 85 D1 B0 00 05 04 00 85 D1 00 03 8F 00 00 FF 5A
00 00 00 Line:345
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 DC 00 00 4C 58
00 00 00 Line:346
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 DD 00 00 4D 57
00 00 00 Line:347
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 DD 00 00 4D 49
00 00 00 Line:348
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 DD 00 00 4D 00
00 00 00 Line:349
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 DE 00 00 4E 57
00 00 00 Line:350

Aug 6 '07 #3
You will miss messages if you are not in the receive method when they
arrive. Normal way to process this is to receive the data and pass the
buffer off to an other thread to process and quickly get back to the
receive methods.

Hope this helps.
Leon Lambert

cm****@hotmail.com wrote:
On Aug 6, 1:24 pm, Peter Duniho <NpOeStPe...@NnOwSlPiAnMk.comwrote:
>cmh...@hotmail.com wrote:
>>I have some code that continually reads packets off of a udp port
where the incoming packets are 26 bytes in length.
[...]
Is
there some way that the buffer would back up where the Receive() calls
would not dequeue?
Not assuming you are actually calling Receive(), no. Receive() consumes
the received data.

You will need to post a concise-but-complete example of code that
reliably reproduces the problem. The single line of code you posted is
not anywhere close to properly representing what you're actually doing
in your code.

Note also that for networking code, "complete" means that you post both
sending and receiving code. For any example, "concise" means that you
reduce the code to the bare minimum required to reproduce the problem.

Pete


Hi Pete,

Line 334 is where the sequence number jumps (byte 21) from BE to FB.
I don't have the code that sends the packets...it's an embedded system
outside of my reach, but I have pasted some source code below for the
receiving portion of the code and the console output. The packets are
all 26 bytes long though. I can see them using Wireshark to verify
their content.

Thanks,

Chris

--------------------------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Windows.Forms;

namespace TestUDP
{
public partial class Form1 : Form
{
bool stopReading = false;

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
UdpClient udpClient = new UdpClient(5002);
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any,
5002);

int lineCounter = 0;

while (!stopReading)
{
byte[] recBytes = udpClient.Receive(ref ipEndPoint);
foreach (byte b in recBytes)
Console.Write(b.ToString("X2") + @" ");
Console.WriteLine(@" Line:" + ++lineCounter);
Application.DoEvents();
}

udpClient.Close();
this.Close();

}

private void button2_Click(object sender, EventArgs e)
{
stopReading = true;
}
}
}

--------------------

CONSOLE OUTPUT --->

00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 4C 00 00 BC 58
00 00 00 Line:307
00 1A B8 00 00 36 00 85 D1 B0 00 02 04 00 85 D1 00 03 4C 00 00 BC 35
00 00 00 Line:308
00 1A B8 00 00 5A 00 85 D1 B0 00 05 04 00 85 D1 00 03 4C 00 00 BC 5A
00 00 00 Line:309
00 1A B8 00 00 52 00 85 D1 B0 00 04 04 00 85 D1 00 03 4C 00 00 BC 42
00 00 00 Line:310
00 1A B8 00 00 3A 00 85 D1 B0 00 03 04 00 85 D1 00 03 4C 00 00 BC 43
00 00 00 Line:311
00 1A B8 00 00 38 00 85 D1 B0 00 06 04 00 85 D1 00 03 4C 00 00 BC 3F
00 00 00 Line:312
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 4C 00 00 BC 4A
00 00 00 Line:313
00 1A B8 00 00 16 00 85 D1 B0 00 00 04 00 85 D1 00 03 4C 00 00 BC 52
00 00 00 Line:314
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 4C 00 00 BC 00
00 00 00 Line:315
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 4D 00 00 BD 58
00 00 00 Line:316
00 1A B8 00 00 36 00 85 D1 B0 00 02 04 00 85 D1 00 03 4D 00 00 BD 35
00 00 00 Line:317
00 1A B8 00 00 5A 00 85 D1 B0 00 05 04 00 85 D1 00 03 4D 00 00 BD 5A
00 00 00 Line:318
00 1A B8 00 00 16 00 85 D1 B0 00 00 04 00 85 D1 00 03 4D 00 00 BD 52
00 00 00 Line:319
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 4D 00 00 BD 4A
00 00 00 Line:320
00 1A B8 00 00 52 00 85 D1 B0 00 04 04 00 85 D1 00 03 4D 00 00 BD 42
00 00 00 Line:321
00 1A B8 00 00 3A 00 85 D1 B0 00 03 04 00 85 D1 00 03 4D 00 00 BD 43
00 00 00 Line:322
00 1A B8 00 00 38 00 85 D1 B0 00 06 04 00 85 D1 00 03 4D 00 00 BD 3F
00 00 00 Line:323
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 4D 00 00 BD 00
00 00 00 Line:324
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 4E 00 00 BE 58
00 00 00 Line:325
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 4E 00 00 BE 4A
00 00 00 Line:326
00 1A B8 00 00 36 00 85 D1 B0 00 02 04 00 85 D1 00 03 4E 00 00 BE 34
00 00 00 Line:327
00 1A B8 00 00 5A 00 85 D1 B0 00 05 04 00 85 D1 00 03 4E 00 00 BE 5A
00 00 00 Line:328
00 1A B8 00 00 16 00 85 D1 B0 00 00 04 00 85 D1 00 03 4E 00 00 BE 52
00 00 00 Line:329
00 1A B8 00 00 52 00 85 D1 B0 00 04 04 00 85 D1 00 03 4E 00 00 BE 42
00 00 00 Line:330
00 1A B8 00 00 3A 00 85 D1 B0 00 03 04 00 85 D1 00 03 4E 00 00 BE 43
00 00 00 Line:331
00 1A B8 00 00 38 00 85 D1 B0 00 06 04 00 85 D1 00 03 4E 00 00 BE 3F
00 00 00 Line:332
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 4E 00 00 BE 00
00 00 00 Line:333
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 8B 00 00 FB 57
00 00 00 Line:334
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 8B 00 00 FB 49
00 00 00 Line:335
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 8B 00 00 FB 00
00 00 00 Line:336
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 8C 00 00 FC 58
00 00 00 Line:337
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 8C 00 00 FC 49
00 00 00 Line:338
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 8D 00 00 FD 58
00 00 00 Line:339
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 8D 00 00 FD 4A
00 00 00 Line:340
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 8D 00 00 FD 00
00 00 00 Line:341
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 8E 00 00 FE 58
00 00 00 Line:342
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 8E 00 00 FE 4A
00 00 00 Line:343
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 8F 00 00 FF 58
00 00 00 Line:344
00 1A B8 00 00 5A 00 85 D1 B0 00 05 04 00 85 D1 00 03 8F 00 00 FF 5A
00 00 00 Line:345
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 DC 00 00 4C 58
00 00 00 Line:346
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 DD 00 00 4D 57
00 00 00 Line:347
00 1A B8 00 00 46 00 85 D1 B0 00 01 04 00 85 D1 00 03 DD 00 00 4D 49
00 00 00 Line:348
00 1A B8 00 00 42 00 85 D1 A0 00 00 03 00 85 D1 00 03 DD 00 00 4D 00
00 00 00 Line:349
00 1A B8 00 00 20 00 85 D1 B0 00 07 04 00 85 D1 00 03 DE 00 00 4E 57
00 00 00 Line:350
Aug 7 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by ma740988 | last post: by
11 posts views Thread by Danny J. Lesandrini | last post: by
5 posts views Thread by Roy Hills | last post: by
4 posts views Thread by Greg Young | last post: by
2 posts views Thread by RG | last post: by
reply views Thread by =?Utf-8?B?QWxmb250eg==?= | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.