title: Socket connection closes on second call from client (C# to PHP)
body: <p>I have written a client in C# and a server in PHP both on localhost and should communicate data through a socket.</p>
  
  <p>I use The following C# code to read from a PHP server:</p>
  
  <pre><code>string getResponse(string request)
  {
      string response = "";
  
      byte[] bytes = new byte[10024];
  
      byte[] msg = Encoding.ASCII.GetBytes(request);
      // Send the data through the socket.
      int bytesSent = Sender.Send(msg);
  
  
      // Receive the response from the remote device.
      int bytesRec = Sender.Receive(bytes);
      response = Encoding.ASCII.GetString(bytes, 0, bytesRec);
  
  
      return response;
  }
  </code></pre>
  
  <p>And Sender, defined and initiated as follows</p>
  
  <pre><code>Socket Sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  IPAddress ipAddress = IPAddress.Parse("127.0.0.1");               
  IPEndPoint remoteEP = new IPEndPoint(ipAddress,8888);           
  Sender.Connect(remoteEP);
  </code></pre>
  
  <p>The code works fine in the first call of <code>getResponse</code>, but in the second call it generates the following error on
  <code>Sender.Receive</code> call:</p>
  
  <blockquote>
    <p>SocketException was unhandled An established connection was aborted by the software in your host machine</p>
  </blockquote>