I have the following in my current app...

VB Code:
  1. Try
  2.             ' Set the TcpListener on port 13000.
  3.             Dim port As Int32 = 13000
  4.             Dim localAddr As IPAddress = IPAddress.Parse("127.0.0.1")
  5.  
  6.             Server = New TcpListener(localAddr, port)
  7.  
  8.             ' Start listening for client requests.
  9.             Server.Start()
  10.  
  11.             ' Buffer for reading data
  12.             Dim bytes(1024) As [Byte]
  13.             Dim data As [String] = Nothing
  14.  
  15.             ' Enter the listening loop.
  16.             While True
  17.                 Debug.Write("Waiting for a connection... ")
  18.  
  19.                 ' Perform a blocking call to accept requests.
  20.                 ' You could also user server.AcceptSocket() here.
  21.                 Dim client As TcpClient = Server.AcceptTcpClient()
  22.                 Debug.WriteLine("Connected!")
  23.  
  24.                 data = Nothing
  25.  
  26.                 ' Get a stream object for reading and writing
  27.                 Dim stream As NetworkStream = client.GetStream()
  28.  
  29.                 Dim i As Int32
  30.  
  31.                 ' Loop to receive all the data sent by the client.
  32.                 i = stream.Read(bytes, 0, bytes.Length)
  33.                 While (i <> 0)
  34.                     ' Translate data bytes to a ASCII string.
  35.                     data = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
  36.                     Debug.WriteLine([String].Format("Received: {0}", data))
  37.  
  38.                     ' Process the data sent by the client.
  39.                     data = CheckValidity(data.ToUpper)
  40.  
  41.                     Dim msg As [Byte]() = System.Text.Encoding.ASCII.GetBytes(data)
  42.  
  43.                     ' Send back a response.
  44.                     stream.Write(msg, 0, msg.Length)
  45.                     Console.WriteLine([String].Format("Sent: {0}", data))
  46.  
  47.                     i = stream.Read(bytes, 0, bytes.Length)
  48.  
  49.                 End While
  50.  
  51.                 ' Shutdown and end connection
  52.                 client.Close()
  53.             End While

This works ok the first time you connect and stuff, but it does not cause the connection to start listening again. It is in a sub that is used to create a thread to listen for incoming connection requests.

The ideal thing to happen would be for a request to come in and be pushed off to another port or something like that so that the main port (the one that is hardcoded into my client) will remain open for more requests...

Any Ideas?

SQ1