Purpose of Program: I want to create a simple program that logs into a
device gets some info and stores that info elsewhere. I just wanted to
see if I could connect and receive the banner that comes up. Currently
the program is in a barebones form.
Problem: I can get connected just fine but I cannot receive the banner
when it comes up. I even added a loop that waits until there are bytes
available before it tries to read. But even when there are bytes
available to read, there is nothing in the buffer to receive.
Any suggestions would be greatly appreciated.
' Data buffer for incoming data.
Dim bytes(2048) As Byte
Dim bytesRec As Integer
' Connect to a remote device.
' Establish the remote endpoint for the socket.
Dim ipAddress As IPAddress = ipAddress.Parse ("10.194.177.6" )
Dim remoteEP As New IPEndPoint(ipAd dress, 23)
' Create a TCP/IP socket.
s = New Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p)
' Connect the socket to the remote endpoint.
s.Connect(remot eEP)
' Clear out the bytes buffer
bytes = Encoding.ASCII. GetBytes("")
TextBox1.Text = "Socket connected to " & s.RemoteEndPoin t.ToString() &
vbCrLf
' Wait until there is something in the devices buffer before try to
read
Do
TextBox1.Text = TextBox1.Text & s.Available.ToS tring & vbCrLf
Loop Until s.Available.ToS tring <> 0 Or s.Connected = False
bytesRec = s.Receive(bytes )
TextBox1.Text = TextBox1.Text & "Echoed test = " &
Encoding.ASCII. GetString(bytes , 0, bytesRec) & " - BytesRec: " &
bytesRec & vbCrLf
'release the socket
s.Shutdown(Sock etShutdown.Both )
s.Close()
device gets some info and stores that info elsewhere. I just wanted to
see if I could connect and receive the banner that comes up. Currently
the program is in a barebones form.
Problem: I can get connected just fine but I cannot receive the banner
when it comes up. I even added a loop that waits until there are bytes
available before it tries to read. But even when there are bytes
available to read, there is nothing in the buffer to receive.
Any suggestions would be greatly appreciated.
' Data buffer for incoming data.
Dim bytes(2048) As Byte
Dim bytesRec As Integer
' Connect to a remote device.
' Establish the remote endpoint for the socket.
Dim ipAddress As IPAddress = ipAddress.Parse ("10.194.177.6" )
Dim remoteEP As New IPEndPoint(ipAd dress, 23)
' Create a TCP/IP socket.
s = New Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p)
' Connect the socket to the remote endpoint.
s.Connect(remot eEP)
' Clear out the bytes buffer
bytes = Encoding.ASCII. GetBytes("")
TextBox1.Text = "Socket connected to " & s.RemoteEndPoin t.ToString() &
vbCrLf
' Wait until there is something in the devices buffer before try to
read
Do
TextBox1.Text = TextBox1.Text & s.Available.ToS tring & vbCrLf
Loop Until s.Available.ToS tring <> 0 Or s.Connected = False
bytesRec = s.Receive(bytes )
TextBox1.Text = TextBox1.Text & "Echoed test = " &
Encoding.ASCII. GetString(bytes , 0, bytesRec) & " - BytesRec: " &
bytesRec & vbCrLf
'release the socket
s.Shutdown(Sock etShutdown.Both )
s.Close()