title: VB.NET Socket Send and Receive
body: <p>I am trying to ping a message to a server and get a message back with a numeric value of total players on the server. Unfortunately the code below freezes unless I remove a piece of the code seen below.</p>
  
  <pre><code>Public Shared Function SocketSendReceive(server As String, port As Integer) As String
      'Set up variables and String to write to the server. 
      Dim ascii As Encoding = Encoding.ASCII
      Dim request As String = (DoubleChar(Len(Chr(35))) + Chr(CheckSum(Chr(35)) * 20 Mod 194) + Chr(0) + Chr(35))
      Dim bytesSent As [Byte]() = ascii.GetBytes(request)
      Dim bytesReceived(255) As [Byte]
  
      ' Create a socket connection with the specified server and port. 
      Dim s As Socket = ConnectSocket(server, port)
  
      If s Is Nothing Then
          Return "0"
      End If
      ' Send request to the server.
      s.Send(bytesSent, bytesSent.Length, 0)
  
      ' Receive the server  home page content. 
      Dim bytes As Int32
  
      ' Read the first 256 bytes. 
      Dim page As [String] = "0"
  
      ' The following will block until the page is transmitted. 
      Do
          bytes = s.Receive(bytesReceived, bytesReceived.Length, 0)
          page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes)
      Loop While bytes &gt; 0
      Return page
  End Function
  </code></pre>
  
  <p>As I remove this part of the code:</p>
  
  <pre><code>    Do
          bytes = s.Receive(bytesReceived, bytesReceived.Length, 0)
          page = page + Encoding.ASCII.GetString(bytesReceived, 0, bytes)
      Loop While bytes &gt; 0
  </code></pre>
  
  <p>The ping goes through but does not return the value. Could somebody point out what I am doing wrong?</p>