Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6 Telnet

Posted on 2010-08-14
11
Medium Priority
?
850 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:souldigital
[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
  • 5
11 Comments
 
LVL 32

Expert Comment

by:DrDamnit
ID: 33439237
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
0
 

Author Comment

by:souldigital
ID: 33443988
Not 100% on this please can you provide some really simplified code?
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 33445779
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.
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:souldigital
ID: 33447133
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
0
 

Author Comment

by:souldigital
ID: 33466681
Any update on this guys?
0
 

Author Comment

by:souldigital
ID: 33473320
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???????????
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 33483779
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
0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 33483780
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

0
 
LVL 32

Expert Comment

by:DrDamnit
ID: 33483784
You just need to receive until you get to vbCrLf in a row that indicate it is done talking for the moment.
0
 

Author Comment

by:souldigital
ID: 33495178
Way to complex for me. Surely there is an easier way with winsock?
0
 
LVL 32

Accepted Solution

by:
DrDamnit earned 2000 total points
ID: 33496227
It's not complex. You just didn't look for the parts that are applicable to you.

anyway... try this:

http://www.15seconds.com/issue/010820.htm

The concept is to concatenate the arrival strings until you get a double vbcrlf, which should signal the end of that transmission. Of course, you may not be getting a double VBCRLF from whatever you're talking to. You have to figure out what the end of transmission bytes are for your application.
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

636 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