title: how to receive data from a Socket in .NET Core?
body: <p>I'm currently porting a hardware library to .NET Core. The communication works over TCP. I have problems with the 'Socket.BeginReceive' method. <a href="https://msdn.microsoft.com/en-us/library/dxkwh6zw(v=vs.110).aspx" rel="nofollow noreferrer">MSDN</a></p>
  
  <p>It seems there is no equivalent method in .NET Core. How can I receive data from a TCP Socket?</p>
  
  <pre><code>private void InternalDataReceived(IAsyncResult ar)
  
  {
      int dataCount = 0;
      byte[] buffer;
  
      try
      {
          if (_client != null &amp;&amp; _client.Client != null)
          {
              dataCount = _client.Client.EndReceive(ar);
          }
  
          if (dataCount &gt; 0)
          {
              try
              {
                  buffer = new byte[dataCount];
                  Array.Copy(_inBuffer, buffer, dataCount);
  
                  if (DataReceived != null)
                  {
                      DataReceived(buffer);
                  }
              }
              catch (Exception exc)
              {
                  if (exc is System.Net.Sockets.SocketException)
                  {
                      Disconnect();
                      return;
                  }
              }
              _client.Client.BeginReceive(_inBuffer, 0, _inBuffer.Length, SocketFlags.None, InternalDataReceived, null);
          }
      }
      catch
      {
          Disconnect();
      }
  }
  </code></pre>