CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2002
    Location
    cosmos
    Posts
    148

    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
    What doesn't kill us makes us stronger. F.Nietzsche.

  2. #2
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    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);
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  3. #3
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    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;
                            }
    }
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  4. #4
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    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
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  5. #5
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    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.
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  6. #6
    Join Date
    Oct 2002
    Location
    cosmos
    Posts
    148

    Re: Problem while sending UDP packet everyone every second.

    After editing like you said, the problem still exist.
    What doesn't kill us makes us stronger. F.Nietzsche.

  7. #7
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    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
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  8. #8
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    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
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured