Hi Everybody,
I'm trying to TELNET to a UNIX server from within my VB .NET proggy.
I can connect up to the server on Port 23, no problem, using a Socket.
My problem is sending commands to the Socket and receiving anything intelligible back.
The only data I'm able to get back from the server is the string below:-
"}} }#}}'}$
This happens on the first pass of the code. If I then disconnect the socket, close it and re-open it, all I get back is an empty string!
Here's the code I'm using (I have never used Sockets before btw!).
VB Code:
Imports System.Net Imports System.Net.Sockets Imports System.Text Class UNIX_Connection Public mySocket As Socket Public IP As IPEndPoint Public Connected As Boolean Public Sub Connect(ByVal Server As String) IP = New IPEndPoint(Dns.GetHostByName(Server).AddressList(0), 23) mySocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Try mySocket.Connect(IP) Connected = True Catch ex As Exception Connected = False End Try End Sub Public Sub SendData(ByVal Message As String) If Connected = False Then MessageBox.Show("No connection exists.") Exit Sub End If Dim Buffer() As Byte = ASCIIEncoding.ASCII.GetBytes(Message) mySocket.Send(Buffer, Buffer.Length, SocketFlags.None) Dim ReceivedData(255) As Byte mySocket.Receive(ReceivedData, 0, mySocket.Available, SocketFlags.None) MessageBox.Show(ASCIIEncoding.ASCII.GetString(ReceivedData)) End Sub Public Sub Disconnect() mySocket.Shutdown(SocketShutdown.Both) mySocket.Close() Connected = False End Sub End Class
Any help would be fantastic.




Reply With Quote