Link to home
Start Free TrialLog in
Avatar of souldigital
souldigital

asked on

VB6 Telnet

Below is the code I am currently using to -

1) Connect to a router
2) Issue a command
3) Disconnect

What I want to do is -

1) Connect to a router
2) Issue a command
3) Output the routers response to a textbox
4) Exit

I have a number of command buttons and want to output the routers responce in seperate textboxes when they are clicked.



Private Sub Winsock1_Connect()
   Winsock1.SendData "admin" & vbCrLf
End Sub

Private Sub Connect_Click()
    h% = FreeFile
      Open "C:\Router.cfg" For Input As #h%
      Line Input #h%, IPAdr$(1)
      Close #h%
      lblIP(0).Caption = IPAdr$(1)
     
    Winsock1.Close
    Winsock1.Connect (IPAdr$(1)), 23
End Sub

Private Sub Nine_Click()
            If Winsock1.State = 0 Then
            PleaseConnect.Show
            Else
    Winsock1.SendData "powerdown" & vbCrLf
    End If
End Sub

Private Sub Disconnect_Click()
    Winsock1.Close
End Sub


Please make this as simple as possible :-s
Avatar of DrDamnit
DrDamnit
Flag of United States of America image

It's pretty easy. Just use a loop and the receive data method of Winsock1 to build a string until you get the CRLF from the sending box. Then, output the string.

http://msdn.microsoft.com/en-us/library/ms740120%28VS.85%29.aspx
Avatar of souldigital
souldigital

ASKER

Not 100% on this please can you provide some really simplified code?
I have some, but it is in a backup from 2 or 3 years ago. Let me see if I can find it. No promises....

Have considered moving to .NET? It's a lot easier (once you get over the learning curve), and VB6 is not only end of life'd, but won't run on Vista / 7.
I only use it now and again for little apps so have never really looked into it. That would be great if you could.

Cheers,

Ben
Any update on this guys?
What would be good is if the code could do the following -

1) Connect to a router

2) Issue a command
3) Output the routers response to a text file

4) Issue another command
5) Output the routers response to another text file

6) Exit

As above I only need to know how to do 2,3,4 and 5.

Any ideas???????????
I forgot I used to use cSocket becaues it was vastly superior in every way to Winsock (it can be programmed into a class).


vbami.txt
All you need from there is this loop:

Private Sub oSocket_OnDataArrival(ByVal bytesTotal As Long)
    Dim strBuffer As String
    strBuffer = Space(bytesTotal)
    oSocket.GetData strBuffer, , bytesTotal
    Debug.Print (strBuffer)
    ProcessMessage (strBuffer)
End Sub

You just need to receive until you get to vbCrLf in a row that indicate it is done talking for the moment.
Way to complex for me. Surely there is an easier way with winsock?
ASKER CERTIFIED SOLUTION
Avatar of DrDamnit
DrDamnit
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial