Problem while sending UDP packet everyone every second.
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?
Code:
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
Re: Problem while sending UDP packet everyone every second.
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.
Code:
this.broadcastSocket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.Broadcast, 1000);
Re: Problem while sending UDP packet everyone every second.
also revise your code like this:
Code:
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;
}
}
Re: Problem while sending UDP packet everyone every second.
also good technical information here:
High-Performance Messaging:
http://www.29west.com/docs/THPM/thpm...-BUFFER-SIZING
Re: Problem while sending UDP packet everyone every second.
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.
Re: Problem while sending UDP packet everyone every second.
After editing like you said, the problem still exist.
Re: Problem while sending UDP packet everyone every second.
did you read the article i sent you?
and this link:
http://www.codeproject.com/KB/IP/gfxscan.aspx
Re: Problem while sending UDP packet everyone every second.
he has used another overload for SendTo in his project:
Code:
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&r...rfill+udp+c%23