title: tcp connection with machine via ethernet using vb.net
body: <p>I want to make a simple formapp using vb.net to send ASCII strings to a machine, that responds after every command. i.e., if i send "AA" it responds "123".</p>
  
  <p>I can already open the connection cause if i check the connection with hyperterminal it says that the port is already being used. Yet, when i send commands i have no answer back.</p>
  
  <p>I kinda adapted the template codes for server/client chat with tcp:</p>
  
  <pre><code>Imports System.Net.Sockets
  Imports System.Threading 
  
  Dim Listener As New TcpListener(65535)
  Dim Client As New TcpClient
  Dim Message As String = "
  
  Private Sub Timer1_Tick(ByVal sender As System.Object, _
          ByVal e As System.EventArgs) Handles Timer1.Tick
  If Listener.Pending = True Then
      Message = ""
  Client = Listener.AcceptTcpClient()
  
  Dim Reader As New StreamReader(Client.GetStream())
  While Reader.Peek &gt; -1
      Message = Message + Convert.ToChar(Reader.Read()).ToString
  End While
  RichTextBox1.ForeColor = Color.Black
  RichTextBox1.Text += Message + vbCrLf
  End Sub
  
  Private Sub btnSend_Click(ByVal sender As System.Object, _
          ByVal e As System.EventArgs) Handles btnSend.Click
  If txtName.Text = "" Or cmbAddress.Text = "" Then
      MessageBox.Show("All Fields must be Filled", _
                      "Error", _
                      MessageBoxButtons.OK, MessageBoxIcon.Error)
  Else
      Try
          Client = New TcpClient(cmbAddress.Text, 65535)
  
          Dim Writer As New StreamWriter(Client.GetStream())
          Writer.Write(txtName.Text &amp; " Says:  " &amp; txtmessage.Text)
          Writer.Flush()
  
          RichTextBox1.Text += (txtName.Text &amp; " Says:  " &amp; txtmessage.Text) + vbCrLf
          txtmessage.Text = ""
      Catch ex As Exception
          Console.WriteLine(ex)
          Dim Errorresult As String = ex.Message
          MessageBox.Show(Errorresult &amp; vbCrLf &amp; vbCrLf &amp; _
                          "Please Review Client Address", _
                          "Error Sending Message", _
                          MessageBoxButtons.OK, MessageBoxIcon.Error)
      End Try
  
  End If
  End Sub
  </code></pre>
  
  <p>is there a muuuuuuuch better way to do this? i read about .net.sockets but i coulndt get out of this. </p>
  
  <p>and the manuals say nothing about how the machine operates. if it's a client, server, host.. can someone help me here? thank you ! </p>