C
Claire
I'm implementing a UDP server socket from the system.net.sockets.socket
class. (no, I don't want to use the udpclient class)
I'm polling the socket in a thread, testing the socket.available property on
each pass.
With datagrams, does socket.available only advertise when there are complete
packets in its buffers?
What i mean to say is that if socket.Available > 0 then there will be at
least 1 whole datagram ready to be read? So, if less than a full datagram
arrived, socket.available would return zero?
I've already noticed that if socket.Available 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.Net.Sockets.AddressFamily.InterNetwork,
System.Net.Sockets.SocketType.Dgram,
System.Net.Sockets.ProtocolType.Udp);
myServerEndpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any,
12345);
myServerSocket.Bind(myServerEndpoint);
while(Condition)
{
Available = myServerSocket.Available;
if (Available > 0)
{
foobar();
}
Thread.Sleep(sleeptime);
}
class. (no, I don't want to use the udpclient class)
I'm polling the socket in a thread, testing the socket.available property on
each pass.
With datagrams, does socket.available only advertise when there are complete
packets in its buffers?
What i mean to say is that if socket.Available > 0 then there will be at
least 1 whole datagram ready to be read? So, if less than a full datagram
arrived, socket.available would return zero?
I've already noticed that if socket.Available 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.Net.Sockets.AddressFamily.InterNetwork,
System.Net.Sockets.SocketType.Dgram,
System.Net.Sockets.ProtocolType.Udp);
myServerEndpoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any,
12345);
myServerSocket.Bind(myServerEndpoint);
while(Condition)
{
Available = myServerSocket.Available;
if (Available > 0)
{
foobar();
}
Thread.Sleep(sleeptime);
}