Click to See Complete Forum and Search --> : Problem while sending UDP packet everyone every second.
sulacco
December 14th, 2008, 03:47 AM
Hi, ppl. The problem is that this function works good. It is sending upd packet.
I use it in timer. So it's goes to net every second. But the problem is that through
some time there is message box appearing and saying that socket buffer is too small or queue is overfill. What is it?
public void SendBroadBandMessage()
{
this.broadcastSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
this.broadcastSocket.SendTimeout = 100;
this.broadcastSocket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1);
byte[] _data = Encoding.ASCII.GetBytes("1234");
IPEndPoint _ipoint = new IPEndPoint(IPAddress.Broadcast, 7777);
try
{
this.broadcastSocket.SendTo(_data, _ipoint);
}
catch (SocketException _so)
{
MessageBox.Show("");
}
this.broadcastSocket.Shutdown(SocketShutdown.Both);
this.broadcastSocket.Close();
this.broadcastSocket = null;
}
ck
toraj58
December 14th, 2008, 06:46 AM
UDP buffer sizes should be large enough to allow an application to endure the normal variance in CPU scheduling latency without suffering packet loss. They should also be small enough to prevent the application from having to read through excessively old data following an unusual spike in CPU scheduling latency.
this.broadcastSocket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1000);
toraj58
December 14th, 2008, 06:51 AM
also revise your code like this:
public void SendBroadBandMessage()
{
this.broadcastSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
this.broadcastSocket.SendTimeout = 100;
this.broadcastSocket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1000);
byte[] _data = Encoding.ASCII.GetBytes("1234");
IPEndPoint _ipoint = new IPEndPoint(IPAddress.Broadcast, 7777);
try
{
this.broadcastSocket.SendTo(_data, _ipoint);
}
catch (SocketException _so)
{
MessageBox.Show(_so.Message);
}
finally
{
this.broadcastSocket.Shutdown(SocketShutdown.Both);
this.broadcastSocket.Close();
this.broadcastSocket = null;
}
}
toraj58
December 14th, 2008, 06:53 AM
also good technical information here:
High-Performance Messaging:
http://www.29west.com/docs/THPM/thpm.html#UDP-BUFFER-SIZING
toraj58
December 14th, 2008, 06:57 AM
take a look at this article:
http://www.codeproject.com/KB/IP/gfxscan.aspx
it is with C++(in .Net) if you look at it carfully you will get some clue also the classes used in it are somewhat same as yours.
sulacco
December 14th, 2008, 09:22 AM
After editing like you said, the problem still exist.
toraj58
December 15th, 2008, 01:23 AM
did you read the article i sent you?
and this link:
http://www.codeproject.com/KB/IP/gfxscan.aspx
toraj58
December 15th, 2008, 01:36 AM
he has used another overload for SendTo in his project:
sock->SendTo(msg, 0, msg->Length, SocketFlags::None, endPoint);
maybe it is the key point.
BTW; if i were you i would download its code and investigating it line by line then try to apply it to my solution.
i did not read the the article completely because at this moment it is not my problem but i had a glance at it and i think it has many clue that what is the origin of the problem and what are solutions;
BTW your problem will be solved soon if you care to them.
in google also:
http://www.google.com/search?hl=en&rls=GBSA%2CGBSA%3A2008-30%2CGBSA%3Aen&q=socket+buffer+is+too+small+or+queue+is+overfill+udp+c%23
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.