VB.Net telnet help needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • john.kramer@ejgallo.com

    VB.Net telnet help needed

    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(B yVal sender As System.Object, ByVal e
    As System.EventArg s) Handles Button1.Click
    Dim telnetclient As New Net.Sockets.Tcp Client
    Dim ns As System.Net.Sock ets.NetworkStre am
    telnetclient.Co nnect("xx.xx.xx .xx", 9999)
    ns = telnetclient.Ge tStream
    Dim data(1024) As Byte
    If ns.CanWrite Then
    Dim myWriteBuffer As Byte() =
    Encoding.ASCII. GetBytes(vbCrLf )
    ns.Write(myWrit eBuffer, 0, myWriteBuffer.L ength)
    myWriteBuffer = Encoding.ASCII. GetBytes("9" & vbCrLf)
    ns.Write(myWrit eBuffer, 0, myWriteBuffer.L ength)
    Else
    Console.WriteLi ne("Sorry. You cannot write to this
    NetworkStream." )
    End If
    End Sub
    End Class

Working...