title: Is this ReceiveFromAsync() bug?
body: <p>this is my first question and I'm not English native speaker so sorry for my (maybe) inaccurate English.</p>
  
  <p>I'm implementing real-time network engine and using Socket.xxxAsync() method.</p>
  
  <p>I made a UDP socket at server-side like this.</p>
  
  <pre><code>m_udpSock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  m_udpSock.Bind(new IPEndPoint(IPAddress.Any, udpPort));
  SocketAsyncEventArgs udpRecvArg = new SocketAsyncEventArgs();
  udpRecvLoopStart(m_udpSock, udpRecvArg);
  </code></pre>
  
  <p>(udpPort is known to client.)</p>
  
  <pre><code>    private void udpRecvLoopStart(Socket udpSocket, SocketAsyncEventArgs udpRecvArg)
      {            
          udpRecvArg.AcceptSocket = udpSocket;
          byte[] udpRecvBuffer = new byte[NetworkEngineConst.MsgSizeMax];
          udpRecvArg.SetBuffer(udpRecvBuffer, 0, udpRecvBuffer.Length);
          udpRecvArg.RemoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
          udpRecvArg.Completed += new EventHandler&lt;SocketAsyncEventArgs&gt;(udpRecvArg_Completed);
  
          udpRecv(udpRecvArg);
      }
  
      private void udpRecv(SocketAsyncEventArgs udpRecvArg)
      { 
          bool synchronous = false;
          try
          {                
              synchronous = !udpRecvArg.AcceptSocket.ReceiveFromAsync(udpRecvArg);
          }
          catch (Exception e)
          {
              OnIOError("recvUdp()\n" + e.ToString());
              return;
          }
          if (synchronous)
              udpRecvArg_Completed(this, udpRecvArg);
      }
  </code></pre>
  
  <p>Completed event handler is this:</p>
  
  <pre><code>    void udpRecvArg_Completed(object sender, SocketAsyncEventArgs udpRecvArg)
      {
          EndPoint udpEp = udpRecvArg.RemoteEndPoint;            
          string msg = Encoding.UTF8.GetString(udpRecvArg.Buffer, 14, udpRecvArg.BytesTransferred - 14);
          Debug.WriteLine(udpEp + " " + msg);
          udpRecv(udpRecvArg);            
      }
  </code></pre>
  
  <p>( first 14 bytes are message prefix,CRC and sequence number)</p>
  
  <p>And two(or more) clients send UDP packet to server.
  ( sending rate is hundreds per second )</p>
  
  <p>For example, client1(192.168.0.1:50113) sends "11111111111111111111111111111", 
  client2(192.168.0.1:59368) sends "2".</p>
  
  <p>But sometimes(not always) endpoint is wrong. log is like below:</p>
  
  <p>192.168.0.1:50113 11111111111111111111111111111</p>
  
  <p>192.168.0.1:50113 11111111111111111111111111111</p>
  
  <p>192.168.0.1:50113 11111111111111111111111111111</p>
  
  <p>192.168.0.1:59368 2</p>
  
  <p>192.168.0.1:59368 2</p>
  
  <p>192.168.0.1:50113 11111111111111111111111111111</p>
  
  <p><strong>192.168.0.1:59368 11111111111111111111111111111</strong> &lt;- wrong part</p>
  
  <p>192.168.0.1:59368 2</p>
  
  <p>192.168.0.1:50113 11111111111111111111111111111</p>
  
  <p>192.168.0.1:50113 11111111111111111111111111111</p>
  
  <p>192.168.0.1:50113 11111111111111111111111111111</p>
  
  <p>192.168.0.1:59368 2</p>
  
  <p>192.168.0.1:50113 11111111111111111111111111111</p>
  
  <p>192.168.0.1:59368 2</p>
  
  <p>192.168.0.1:59368 2</p>
  
  <p>I doubt packet error, but there was no error in packet(I confirmed with Wireshark)</p>
  
  <p>Is this a bug ?</p>
  
  <p>(Add)</p>
  
  <p>I tried </p>
  
  <pre><code>        m_udpSock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
          m_udpSock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.PacketInformation, true);
          m_udpSock.Bind(new IPEndPoint(IPAddress.Any, udpPort));
  </code></pre>
  
  <p>and replaced ReceiveFromAsync() with ReceiveMessageFromAsync().</p>
  
  <p>but SocketAsyncEventArgs.ReceiveMessageFromPacketInfo.Address is null</p>
  
  <p>(Add)
  ReceiveMessageFromAsync() problem is a bug.</p>
  
  <p>It is fixed in the .NET framework 4.0</p>
  
  <p><a href="http://connect.microsoft.com/VisualStudio/feedback/details/543700/net-framework-3-5-socket-receivemessagefrom-leaves-ippacketinformation-empty" rel="nofollow">here</a></p>
  
  <p>thank you.</p>