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:
  1. Imports System.Net
  2. Imports System.Net.Sockets
  3. Imports System.Text
  4.  
  5. Class UNIX_Connection
  6.  
  7. Public mySocket As Socket
  8. Public IP As IPEndPoint
  9. Public Connected As Boolean
  10.  
  11. Public Sub Connect(ByVal Server As String)
  12.  
  13. IP = New IPEndPoint(Dns.GetHostByName(Server).AddressList(0), 23)
  14. mySocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
  15. Try
  16. mySocket.Connect(IP)
  17. Connected = True
  18. Catch ex As Exception
  19. Connected = False
  20. End Try
  21.  
  22. End Sub
  23.  
  24. Public Sub SendData(ByVal Message As String)
  25.  
  26. If Connected = False Then
  27. MessageBox.Show("No connection exists.")
  28. Exit Sub
  29. End If
  30.  
  31. Dim Buffer() As Byte = ASCIIEncoding.ASCII.GetBytes(Message)
  32. mySocket.Send(Buffer, Buffer.Length, SocketFlags.None)
  33.  
  34. Dim ReceivedData(255) As Byte
  35. mySocket.Receive(ReceivedData, 0, mySocket.Available, SocketFlags.None)
  36.  
  37. MessageBox.Show(ASCIIEncoding.ASCII.GetString(ReceivedData))
  38.  
  39. End Sub
  40.  
  41. Public Sub Disconnect()
  42.  
  43. mySocket.Shutdown(SocketShutdown.Both)
  44. mySocket.Close()
  45. Connected = False
  46.  
  47. End Sub
  48.  
  49. End Class

Any help would be fantastic.