Hello, everyone. I have researched this problem for aabout 2 days now, and am getting no closer to a solution. I am trying to open a simple TelNet connection to a UNIX server, login, and send some commands. Using code from MSDN, I learned about using the TCPClient to do this. No matter what string I send to the server, I get the same response. It appears that my conversion from text to ASCII works, when using the line
/////////////////Code//////////////////////////////
///////////////////////////////////////////////////
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)
Yet when I try to decode the response from the server, using
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
I get a response of "??$". No matter what string I send, I get the same response. I am pretty sure the connection to the server is working, because if I change the connection port from 23, I get an immediate exception. Am I missing something? Do I need to send a different command? I'm pretty new to UNIX, so I wouldn't be surprised if I'm doing something wrong there. I tried to research standard UNIX commands, but saw nothing different to send aside from "login" to begin the login process to the server. Here is the code I'm using:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim port As Int32 = 23
Dim server As String = "Optim"
Dim client As New TcpClient(server, port)
Dim message As String = "login"
'Translate the passed message into ASCII and store it as a byte array
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)
'Get a client stream for reading and writing
Dim stream As NetworkStream = client.GetStream()
'Send the message to the connected TCPServer
stream.Write(data, 0, data.Length)
Response.Write(
"Sent " & message & "<br />")
'Receive the TCPServer response
'Buffer to store the response bytes
data =
New [Byte](256) {}
'String to store the response ASCII representation
Dim responseData As [String] = [String].Empty
'Read the first batch of the TCPServer response bytes
Dim bytes As Int32 = stream.Read(data, 0, data.Length)
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
Response.Write(
"Received " & responseData & "<br />")
'Close
client.Close()
End Sub
////////////////End Code///////////////
////////////////////////////////////////
Thanks for any help you can provide.
---------------
Mark Struzinski
/////////////////Code//////////////////////////////
///////////////////////////////////////////////////
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)
Yet when I try to decode the response from the server, using
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
I get a response of "??$". No matter what string I send, I get the same response. I am pretty sure the connection to the server is working, because if I change the connection port from 23, I get an immediate exception. Am I missing something? Do I need to send a different command? I'm pretty new to UNIX, so I wouldn't be surprised if I'm doing something wrong there. I tried to research standard UNIX commands, but saw nothing different to send aside from "login" to begin the login process to the server. Here is the code I'm using:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim port As Int32 = 23
Dim server As String = "Optim"
Dim client As New TcpClient(server, port)
Dim message As String = "login"
'Translate the passed message into ASCII and store it as a byte array
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)
'Get a client stream for reading and writing
Dim stream As NetworkStream = client.GetStream()
'Send the message to the connected TCPServer
stream.Write(data, 0, data.Length)
Response.Write(
"Sent " & message & "<br />")
'Receive the TCPServer response
'Buffer to store the response bytes
data =
New [Byte](256) {}
'String to store the response ASCII representation
Dim responseData As [String] = [String].Empty
'Read the first batch of the TCPServer response bytes
Dim bytes As Int32 = stream.Read(data, 0, data.Length)
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
Response.Write(
"Received " & responseData & "<br />")
'Close
client.Close()
End Sub
////////////////End Code///////////////
////////////////////////////////////////
Thanks for any help you can provide.
---------------
Mark Struzinski