Good Afternoon,

I am building a client-server type applications and they are communicating over sockets. This is the first time I am doing such a program and I have been learning off a web example and thought I understood it all but it would appear I am missing something as it starts to work then errors. Here is what I have:

VB Code:
  1. Dim serverSocket As New TcpListener(ListeningPort)
  2.             Dim clientSocket As TcpClient
  3.             Dim netStream As NetworkStream
  4.             Dim BytesFrom(1024) As Byte
  5.             Dim DataFromClient As String
  6.             Dim ServerResponse As String
  7.             Dim BytesTo As [Byte]()
  8.  
  9.             serverSocket.Start()
  10.  
  11.             clientSocket = serverSocket.AcceptTcpClient()
  12.  
  13.           netStream = clientSocket.GetStream
  14.  
  15.             'SEND TO CLIENT
  16.             ServerResponse = "IDENTIFY"
  17.             BytesTo = Encoding.ASCII.GetBytes(ServerResponse)
  18.             netStream.Write(BytesTo, 0, BytesTo.Length)
  19.             netStream.Flush()

All of the above works and if I open up a telnet command window I can connect to my machine running this code on my specified port and in the command prompt window 'IDENTIFY' appears as it should from the above code.

But it then gets to this block an errors on the second line:

VB Code:
  1. 'RECEIVE FROM CLIENT
  2.             netStream = clientSocket.GetStream()
  3.             netStream.Read(BytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
  4.             DataFromClient = System.Text.Encoding.ASCII.GetString(BytesFrom)

Now as far as I can tell it shouldn't be processing the first line [ netStream = clientSocket.GetStream() ]

until I send something back from the client because then going on to the second line its trying to process something that isn't there yet.

The actual error I get is:

Specified argument was out of the range of valid values. Parameter name: size

on the line:

netStream.Read(BytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))


Am I missing something here?