Solved

Cannot use Winsock control on telnet session

Posted on 2001-07-24
10
467 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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
 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

808 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