Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cannot use Winsock control on telnet session

Posted on 2001-07-24
10
Medium Priority
?
479 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

688 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