473,386 Members | 1,715 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,386 software developers and data experts.

How to clear the intenal buffer of a socket?

Hi,

I'm writing a UDP Listener to monitor all incoming UDP messages:

private void ReceiveThreadFkt()
{
EndPoint recEP =new IPEndPoint(IPAddress.Any,6000);
while(false == receiveThreadAbort)
{
// Allow thread to sleep completely
if(receiveThreadSleep == false)
{
// Read data if available, else sleep 10 ms
if((0 != udpSocket.Available))
{
byte[] buffer = new byte[udpSocket.Available];
udpSocket.ReceiveFrom(buffer,ref recEP);
ReceiveQueueElement newElement = new
ReceiveQueueElement(buffer,(IPEndPoint)recEP);
lock(receiveQueue.SyncRoot)
{
receiveQueue.Enqueue(newElement);
}

}
else
{ //no bytes available -> sleep 10 ms
Thread.Sleep(10);
}
}
else
{ // if suspended, sleep for 0.3 seconds
Thread.Sleep(300);
}
}
}

As you can see, this thread can be set to a kind of sleep mode, but when it
is waken up again, all the udp messages stored within the socket are read out.
Is there a possibility to clear the socket's internal buffer, so that the
data which arrived while in sleep mode can be flushed??

Thanks,

Robin
Jul 29 '05 #1
0 1397

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stephan Steiner | last post by:
Hi I have a networking application that periodically needs to go into sleep mode (from an application point of view, I'm simply suspending the receiver thread until it's time to start listening...
0
by: Robin the Round | last post by:
Hi, I'm writing a UDP Listener to monitor all incoming UDP messages: private void ReceiveThreadFkt() { EndPoint recEP =new IPEndPoint(IPAddress.Any,6000); while(false == receiveThreadAbort)...
2
by: Macca | last post by:
Hi, My application uses an asynchronous socket server. The question I have is what i should set my socket server buffer size to. I will know the size of each data packet sent across the...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
16
by: Matthew Geyer | last post by:
been using asynchronous sockets with AsyncCallback and System.Net.Sockets as per the excellent MSDN example. everything has been working great, except when i want to receive more total bytes...
0
by: george585 | last post by:
Hello! I am new to network programming, and understand just basics. Using some sample code, and having read documentation, I managed to create a simple app in C# and VB.NET. The application is...
2
by: manasap | last post by:
Hi all! I've written a server and a client application using asynchronous sockets.The client sends data packets for every 7 seconds.The server receives the packets. This process proceeds...
4
by: Zytan | last post by:
This may be the dumbest question of all time, but... When I set the packet size, does it mean ALL packets are that size, no matter what? Let's say the packet size is 8KB, and I send a 5 byte...
1
by: keksy | last post by:
Hi every1, I am writing a small client/server application and in it I want to send an image asynchronous from the client to the server through a TCP socket. I found an example code on the MSDN...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.