Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 484
  • Last Modified:

Cannot use Winsock control on telnet session

Is is possible to use winsock control to open a telnet session?

I used winsock to open ftp and smtp successful, but fail on get respond from telnet session.

Any alternative way to talk with telnet using VB?

Thanks.
0
saikit
Asked:
saikit
  • 6
  • 3
1 Solution
 
inthedarkCommented:
Winock does work with Telnet so either your code needs enhancing or the server is not listening for telnet. First try connecting to the server via Windows Telnet.exe, just to prove it works, then post your code here.
0
 
saikitAuthor Commented:
My code is as below:
-----------------------

Private Sub ConnectTelnet_Click()
   Dim strData As String
   Winsock1.Connect "172.22.23.6", 23
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
   Dim strData As String
   Winsock1.GetData strData
   Debug.Print strData
End Sub

------------------------
The resume of strData is not a readable characters. It should be the greeting message of my Linux box.

Please help. Thank you very much.
0
 
inthedarkCommented:
Try:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim Answer As String
   
    Answer = String$(bytesTotal, 0)
   
    If winsock1.State = sckConnected Then
        winsock1.GetData Answer, vbString, bytesTotal
        Debug.Print Answer
    End If
   
End Sub
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
saikitAuthor Commented:
I have jusr tried your code.
The result is same.. not working.

In the debug windows return a string "????"
(Four question mark with spaces)
0
 
inthedarkCommented:
Don't forget the the telnet host is expecting you to be a dum terminal and will be expecting you to understand control codes.  So you may need to decode the data before displaying it.  For example ansi bbs, etc.


I don't use the connect syntax that you are using I use something like:

Private Sub cmdConnect_Click()
    If Me.wSock.State = sckClosed Then
        ' First connect to server.
        Me.wSock.RemoteHost = txtHost.Text
       
        Me.wSock.RemotePort = Val(txtPort.Text) ' normally 23
        Me.wSock.LocalPort = 0
        Me.wSock.Connect
        Me.wSock.Protocol = sckTCPProtocol

        Do While True
            If Me.wSock.State = sckConnected Then
                Exit Do
            ElseIf Me.wSock.State = sckError Then
                MsgBox "Impossible to connect to server.", vbExclamation + vbOKOnly, "Error connecting."
                Exit Sub
            End If
            DoEvents
        Loop
    Else
        MsgBox "Please disconnect before connecting again.", vbInformation, "Error connecting."
        Exit Sub
    End If
    statusB.SimpleText = "Connected to " + txtHost.Text + ". Local IP adress : " + wSock.LocalIP + ". Remote host IP : " + wSock.RemoteHostIP + "."
    statusB.Refresh
   
End Sub

0
 
inthedarkCommented:
Sorry I did protocol in formload and just dropped it in without thinking exchange these lines:
 Me.wSock.Connect
 Me.wSock.Protocol = sckTCPProtocol

like:
 Me.wSock.Protocol = sckTCPProtocol
 Me.wSock.Connect
0
 
inthedarkCommented:
Further the response may not be ascii.
0
 
saikitAuthor Commented:
I followed and tried your code for connecting (set protocol to TCP before connect), but the result is same as before (four questions mark & spaces returned). Not working.

How to get the response to be readable character?
0
 
inthedarkCommented:
Have you tried looking somewhere like here for a working example:

http://www.planet-source-code.com/xq/ASP/txtCodeId.11025/lngWId.1/qx/vb/scripts/ShowCode.htm
0
 
DanRollinsCommented:
Hi saikit,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept inthedark's comment(s) as an answer.

saikit, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now