I need a VB.NET app that allows me to connect to a device using
telnet, send two commands (the second of which terminates the
connection), then confirm that the connection is terminated. If I
telnet normally through Windows, I connect, hit the <ENTERat the
first prompt, wait for the second prompt, then press 9 and then
<ENTERagain. At this point te device reboots and I get disconnected.
The code I've attempted (but failed at) is below. I'm new to this type
of thing, so don't laugh too hard. Thanks in advance for any help.
Imports System.Text
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim telnetclient As New Net.Sockets.TcpClient
Dim ns As System.Net.Sockets.NetworkStream
telnetclient.Connect("xx.xx.xx.xx", 9999)
ns = telnetclient.GetStream
Dim data(1024) As Byte
If ns.CanWrite Then
Dim myWriteBuffer As Byte() =
Encoding.ASCII.GetBytes(vbCrLf)
ns.Write(myWriteBuffer, 0, myWriteBuffer.Length)
myWriteBuffer = Encoding.ASCII.GetBytes("9" & vbCrLf)
ns.Write(myWriteBuffer, 0, myWriteBuffer.Length)
Else
Console.WriteLine("Sorry. You cannot write to this
NetworkStream.")
End If
End Sub
End Class