473,408 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 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 3850
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: ma740988 | last post by:
A few days ago I recieved yet again advice on implementing a buffer of bytes. At issue: (part 1) how do I take the contents of a struct, then dump (used sparingly) it into a byte buffer. ...
11
by: Danny J. Lesandrini | last post by:
Has anyone else noticed this? I searched group archives and found nothing, but it's really starting to irritate me big time. Here's the steps to reproduce the problem: Copy something to the...
5
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
4
by: Greg Young | last post by:
Ok so I think everyone can agree that creating buffers on the fly in an async socket server is bad ... there is alot of literature available on the problems this will cause with the heap. I am...
6
by: nickdu | last post by:
I usually try to stay away from _alloca(). However, I'm considering using it for a logging function. Our current logging function maintains its own buffer which it grows to fit the string being...
0
by: Anthony Baxter | last post by:
SECURITY ADVISORY Buffer overrun in repr() for UCS-4 encoded unicode strings http://www.python.org/news/security/PSF-2006-001/ Advisory ID: PSF-2006-001 Issue Date: October 12, 2006...
2
by: RG | last post by:
I am having trouble parsing the data I need from a Serial Port Buffer. I am sending info to a microcontroller that is being echoed back that I need to remove before I start the actual important...
0
by: =?Utf-8?B?QWxmb250eg==?= | last post by:
Looking for some insight into an issue with a MS Word 2003 addin using class serialization to store data. When using firewall software with a ‘Buffer Overflow Exploit Prevention’ feature,...
36
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.