Solved

Cannot use Winsock control on telnet session

Posted on 2001-07-24
10
458 Views
Last Modified: 2013-11-13
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
Comment
Question by:saikit
  • 6
  • 3
10 Comments
 
LVL 17

Expert Comment

by:inthedark
ID: 6316058
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
 

Author Comment

by:saikit
ID: 6316110
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
 
LVL 17

Expert Comment

by:inthedark
ID: 6316246
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
 

Author Comment

by:saikit
ID: 6316276
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
 
LVL 17

Expert Comment

by:inthedark
ID: 6316387
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Expert Comment

by:inthedark
ID: 6316400
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
 
LVL 17

Expert Comment

by:inthedark
ID: 6316425
Further the response may not be ascii.
0
 

Author Comment

by:saikit
ID: 6316438
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
 
LVL 17

Accepted Solution

by:
inthedark earned 100 total points
ID: 6316949
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7161517
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 79
wordcount challenge 11 109
Microsoft Access combo box help 2 38
CONDITIONAL MAX STATEMENT IN T-SQL 3 40
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This video teaches viewers about errors in exception handling.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now