title: C# .NET UDP Sockets Async for Multiple Clients
body: <p>I have been looking around and I can't really find what I need, especially for UDP.</p>
  
  <p>I'm trying to make a basic syslog server listening on port 514 (UDP).</p>
  
  <p>I have been following Microsoft's guide on MSDN: <a href="https://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.beginreceive(v=vs.110).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.beginreceive(v=vs.110).aspx</a></p>
  
  <p>It doesn't clearly state (or I'm blind) how to re-open the connection for more packets to be recieved.</p>
  
  <p>Here is my code (basically the same from the link)</p>
  
  <pre><code>     static void Main(string[] args)
      {
          try
          {
              ReceiveMessages();
  
              Console.ReadLine();
  
          }catch(SocketException ex)
          {
              if(ex.SocketErrorCode.ToString() == "AddressAlreadyInUse")
              {
                  MessageBox.Show("Port already in use!");
              }
          }
  
      }
  
      public static void ReceiveMessages()
      {
          // Receive a message and write it to the console.
  
  
  
          UdpState s = new UdpState();
  
          Console.WriteLine("listening for messages");
          s.u.BeginReceive(new AsyncCallback(ReceiveCallback), s);
          RecieveMoreMessages(s);
      }
  
      public static void RecieveMoreMessages(UdpState s)
      {
          s.u.BeginReceive(new AsyncCallback(ReceiveCallback), s);
      }
  
      public static void ReceiveCallback(IAsyncResult ar)
      {
          UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).u;
          IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).e;
  
          Byte[] receiveBytes = u.EndReceive(ar, ref e);
          string receiveString = Encoding.ASCII.GetString(receiveBytes);
  
          Console.WriteLine("Received: {0}", receiveString);
      }
  </code></pre>
  
  <p>I have tried reiteration but I'm running into 'Running out of buffer space' error from the socket after 2 transactions.</p>
  
  <p>Any ideas?</p>