This is the code i have for the server app, I know its good because ive used it before now i need some code that will let me send text to the server from a text box when i click a button because i lost that code snippet when i formated my hard drive.


VB Code:
  1. Class MyTcpListener
  2.  
  3.     Public Shared Sub Main()
  4.  
  5.         Try
  6.             ' Set the TcpListener on port 13000.
  7.  
  8.             ' Buffer for reading data
  9.             Dim bytes As Byte()
  10.  
  11.  
  12.             ' Enter the listening loop.
  13.             'While True
  14.             If Mainfrm.txtlbl.Text = String.Empty Then
  15.                 Mainfrm.txtlbl.Text = ("Waiting for a connection... ")
  16.                 Mainfrm.txtlbl.ForeColor = Color.Orange
  17.             End If
  18.             ' Perform a blocking call to accept requests.
  19.             ' You could also user server.AcceptSocket() here.
  20.             'If Not server.AcceptTcpClient Is Nothing Then
  21.             If server.Pending = True Then
  22.                 Dim client As TcpClient = server.AcceptTcpClient()
  23.  
  24.  
  25.                 cmand = Nothing
  26.  
  27.                 ' Get a stream object for reading and writing
  28.                 Dim stream As NetworkStream = client.GetStream()
  29.  
  30.                 Dim i As Int32
  31.  
  32.                 ' Loop to receive all the data sent by the client.
  33.  
  34.                 ReDim bytes(1000) 'stream.ToString.Length)
  35.                 i = stream.Read(bytes, 0, bytes.Length)
  36.                 While (i <> 0)
  37.                     ' Translate data bytes to a ASCII string.
  38.                     cmand = System.Text.Encoding.ASCII.GetString(bytes, 0, i)
  39.  
  40.                     Mainfrm.txtlbl.Text = (NewLine & cmand)
  41.  
  42.  
  43.                     ' Process the data sent by the client.
  44.                     cmand = cmand '.ToUpper()
  45.  
  46.                     Dim msg As [Byte]() = System.Text.Encoding.ASCII.GetBytes("Message Received")
  47.  
  48.                     ' Send back a response.
  49.                     stream.Write(msg, 0, msg.Length)
  50.  
  51.                     i = stream.Read(bytes, 0, bytes.Length)
  52.  
  53.                 End While
  54.                 cmd = cmand
  55.                 ' Shutdown and end connection
  56.                 client.Close()
  57.                 'End If
  58.                 'Else
  59.                 'server.Stop()
  60.             End If
  61.             'End While
  62.         Catch e As SocketException
  63.             MessageBox.Show("Error: " & e.Message)
  64.  
  65.         End Try
  66.  
  67.     End Sub 'Main
  68.  
  69. End Class 'MyTcpListener