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);
} 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."
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); } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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
|
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...
|
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...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |