title: UDP Socket receive fails in wp7
body: <p>I am newbie for WP7 and Socket programming. I have gone through msdn sample code <a href="http://msdn.microsoft.com/en-us/library/hh202864%28v=VS.92%29.aspx#Y4537" rel="nofollow">http://msdn.microsoft.com/en-us/library/hh202864(v=VS.92).aspx#Y4537</a> and tested for use. Send works fine but it couldn't receive, this is the code I have used for receiving udp packet data.</p>
  
  <p>In this my Breakpoint always fails @ <code>if (e.SocketError == SocketError.Success)</code></p>
  
  <pre><code>    public string Receive(int portNumber)
      {
          string response = "Operation Timeout";
  
          // We are receiving over an established socket connection
          if (_socket != null)
          {
              // Create SocketAsyncEventArgs context object
              SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
              socketEventArg.RemoteEndPoint = new IPEndPoint(IPAddress.Any, portNumber);
  
              // Setup the buffer to receive the data
              socketEventArg.SetBuffer(new Byte[MAX_BUFFER_SIZE], 0, MAX_BUFFER_SIZE);
  
              // Inline event handler for the Completed event.
              // Note: This even handler was implemented inline in order to make this method self-contained.
              socketEventArg.Completed += new EventHandler&lt;SocketAsyncEventArgs&gt;(delegate(object s, SocketAsyncEventArgs e)
              {
                  try
                  {
                      if (e.SocketError == SocketError.Success)
                      {
                          // Retrieve the data from the buffer
                          response = Encoding.UTF8.GetString(e.Buffer, e.Offset,e.BytesTransferred);
                          response = response.Trim('\0');
                      }
                      else
                      {
                          response = e.SocketError.ToString();
                      }
                      _clientDone.Set();
                  }
                  catch (Exception ex)
                  {
                      ex.ToString();
                  }
  
              });
  
              // Sets the state of the event to nonsignaled, causing threads to block
              _clientDone.Reset();
  
              // Make an asynchronous Receive request over the socket
              _socket.ReceiveFromAsync(socketEventArg);
  
  
              // Block the UI thread for a maximum of TIMEOUT_MILLISECONDS milliseconds.
              // If no response comes back within this time then proceed
              _clientDone.WaitOne(TIMEOUT_MILLISECONDS);
          }
          else
          {
              response = "Socket is not initialized";
          }
  
          return response;
      }
  </code></pre>