Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.00 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Test telnet communication on remote computer using VB.net?
  2. Try
  3.  
  4.    Dim telnetServerIp As String = "192.168.100.55"
  5.    Dim telnetPort As Integer = 23
  6.    Dim client As New TcpClient(telnetServerIp, telnetPort)
  7.    MessageBox.Show("Server is reachable")
  8. Catch Exception ex
  9.    MessageBox.Show("Could not reach server")
  10. End Try
  11.        
  12. // Create a TcpClient.
  13.     // Note, for this client to work you need to have a TcpServer
  14.     // connected to the same address as specified by the server, port
  15.     // combination.
  16.     Int32 port = 13000;
  17.     TcpClient client = new TcpClient(server, port);
  18.  
  19.     // Translate the passed message into ASCII and store it as a Byte array.
  20.     Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);        
  21.  
  22.     // Get a client stream for reading and writing.
  23.    //  Stream stream = client.GetStream();
  24.  
  25.     NetworkStream stream = client.GetStream();
  26.  
  27.     // Send the message to the connected TcpServer.
  28.     stream.Write(data, 0, data.Length);
  29.  
  30.     Console.WriteLine("Sent: {0}", message);