473,587 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket.Availabl e and UDP datagrams

I'm implementing a UDP server socket from the system.net.sock ets.socket
class. (no, I don't want to use the udpclient class)
I'm polling the socket in a thread, testing the socket.availabl e property on
each pass.
With datagrams, does socket.availabl e only advertise when there are complete
packets in its buffers?
What i mean to say is that if socket.Availabl e > 0 then there will be at
least 1 whole datagram ready to be read? So, if less than a full datagram
arrived, socket.availabl e would return zero?
I've already noticed that if socket.Availabl e is greater than the size of a
single datagram Socket.Read method returns a single datagram leaving the
remainder of the bytes in a buffer ready to be collected with subsequent
calls to socket.read (even if you ask for the whole buffer)
Hoping that someone else will have studied the socket classes' behaviour.
thanks

Example server UDP dotnet socket code
myServerSocket = new Socket(System.N et.Sockets.Addr essFamily.Inter Network,
System.Net.Sock ets.SocketType. Dgram,
System.Net.Sock ets.ProtocolTyp e.Udp);
myServerEndpoin t = new System.Net.IPEn dPoint(System.N et.IPAddress.An y,
12345);
myServerSocket. Bind(myServerEn dpoint);
while(Condition )
{
Available = myServerSocket. Available;
if (Available > 0)
{
foobar();
}
Thread.Sleep(sl eeptime);
}
Nov 17 '05 #1
2 6354
Hi Claire,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know if socket.availabl e
only advertise when there are complete packets in its buffers. If there is
any misunderstandin g, please feel free to let me know.

As far as I know, it has to return the size of the first message when a
complete message is available in buffer. According to MSDN, if you are
using a message-oriented socket type such as Dgram, the available data is
the first message in that buffer. If no data is queued in the network
buffer, Available returns 0.

So there are complete messages in buffer, it returns the size of the first
one. Or it returns 0.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #2
Unless you have some need not given here, polling like this is very
inefficient for a service. Instead, block on Receive(). The thread will
wait/block until a whole datagram arrives.

--
William Stacey [MVP]

"Claire" <cz*********@co mmunity.nospam> wrote in message
news:ei******** ******@TK2MSFTN GP15.phx.gbl...
I'm implementing a UDP server socket from the system.net.sock ets.socket
class. (no, I don't want to use the udpclient class)
I'm polling the socket in a thread, testing the socket.availabl e property
on each pass.
With datagrams, does socket.availabl e only advertise when there are
complete packets in its buffers?
What i mean to say is that if socket.Availabl e > 0 then there will be at
least 1 whole datagram ready to be read? So, if less than a full datagram
arrived, socket.availabl e would return zero?
I've already noticed that if socket.Availabl e is greater than the size of
a single datagram Socket.Read method returns a single datagram leaving the
remainder of the bytes in a buffer ready to be collected with subsequent
calls to socket.read (even if you ask for the whole buffer)
Hoping that someone else will have studied the socket classes' behaviour.
thanks

Example server UDP dotnet socket code
myServerSocket = new Socket(System.N et.Sockets.Addr essFamily.Inter Network,
System.Net.Sock ets.SocketType. Dgram,
System.Net.Sock ets.ProtocolTyp e.Udp);
myServerEndpoin t = new System.Net.IPEn dPoint(System.N et.IPAddress.An y,
12345);
myServerSocket. Bind(myServerEn dpoint);
while(Condition )
{
Available = myServerSocket. Available;
if (Available > 0)
{
foobar();
}
Thread.Sleep(sl eeptime);
}

Nov 17 '05 #3

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

Similar topics

2
3084
by: David Konerding | last post by:
Hello, I have written an app which opens a TCP connection to a server and uses a protocol to communicate with it. Specifically, I've written a python IMD client for the molecular dynamics application 'NAMD' (do searches for IMD and NAMD if you want to learn more). The protocol is very simple: both ends of the TCP connection can send...
4
3485
by: Ajay | last post by:
hi! whats the maximum number of datagrams that can queue up on a UDP server socket? or is that system dependent? i have some code that iteratively handles datagrams, and while testing it, i noticed that it responds to at most 3 datagrams (i tried sending 4, 6, 8 and 10 datagrams / second) is that a system dependent feature or can i change...
4
41828
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 to incoming packets again). The packets I'm interested in are UDP broadcasts, so they are simply dropped when nobody application is listening at the...
3
7790
by: Stephan Steiner | last post by:
Hi I have a small program listening to UDP broadcast datagrams that are periodically sent out. It will stop listening for a certain period if either a sufficient number of packets has been received (this is triggered from a class not in the sample code), or if there has been no data on the net for a certain period. During the time where I...
1
3067
by: Rolln_Thndr | last post by:
I'm vey new to network programing and have a few rather fundemental questions. I'm creating a very basic UDP proxy server and having a few issues regarding the sockets. Is it possible to change the properties of a socket WITHOUT closing it and creating a new one? Basically, I need to change the port of a bound socket, but the only way I...
10
5295
by: feel52 | last post by:
Below you'll find the code i'm working on. It's in a button click routine and hangs after 3 or 4 sometimes 5 loops done, probably in sock.receive(....). Some code was found here( on google i mean) but the amazing( at least for me) is that if i run the program step by step or i cancel the loop and run it by pressing the button again and...
6
9782
by: J Rice | last post by:
Hi, I feel like I should apologize in advance because I must be missing something fairly basic and fundamental here. I don't have a book on Python network programming (yet) and I haven't been able to find an answer on the net so far. I am trying to create a pair of programs, one (the client) will be short-lived (fairly) and the second...
14
25249
by: DaTurk | last post by:
I am makeing a Multicast server client setup and was wondering what the difference is between Socket.Connect, and Socket.Bind. It may be a stupid question, but I was just curious. Because I tried a test, and I can't bind two sockets to the same port/ip but I can connect with one socket, and bind with another to the same ip/port. Thanks
0
3563
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 supposed to do the following: monitor ALL INCOMING TCP traffic on the local computer, and save certain parts of it as files - not log files though, but...
0
7920
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8215
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1189
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.