Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need my VFP app to telnet. Any advice? 1

Status
Not open for further replies.

captsnappy

Programmer
Feb 19, 2009
107
US
First time I've needed to do this: my program needs to establish a telnet session on the local LAN, send some commands based on variable values then close the session. My gut reaction is to create a batch file and run that. But I see some posts here related to the winsock-active-x thing. Is this the way to go?

Just don't want start going down the wrong path if I can help it as I need to pump this out pronto.

TIA

trey
 
Well, it depends. Whatever works best for you. But I have done some Telnet with VFP and it works fine for what I need it to do.

If you want to see an example I made, follow the link in my signature and scroll down until you see the "VFP Telnet Client".
Feel free to use it as you see fit.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Thanks, Dave. I had looked at your VFP Telnet Client but could never get it to connect - it would just freeze and I'd have to use Task Mangler to kill VFP. Looking at your code didn't help me but that's because I have never dealt with ActiveX or winsock before.
Any ideas why my Connect freezes?
Trey
 
I'm guessing it's because you are using VFP 9 and when I wrote that screen, I goofed and only allowed for VFP 6 and 7. It there fore doesn't handle events properly. My apologies.
Copy the following code and paste it into the Click method of command button "cmdConnet".

Code:
*** ActiveX Control Event ***
WITH THISFORM.oleSock
   IF .state != 0
      *... The connection isn't idle ... we simply close it
      .OBJECT.CLOSE()
   ENDIF
   .protocol = 0  && TCP
   *... Remote Host name
   .remoteHost = ALLTRIM(THISFORM.txtHostName.VALUE)

   *... Remote Port  
   .remotePort = THISFORM.txtHostPort.VALUE

   *... '0' to use any available Local Port.  If you've opened a port
   *...   before, you'll have to wait for the ip stack to release it 
   *...   before it can be reused.
   .localPort = 0
   .OBJECT.CONNECT()
   STORE INT(SECONDS()) TO ntime
   DO WHILE .OBJECT.state # 7 
      IF !('Visual FoxPro 06' $ VERSION())
         INKEY(.1)
      ENDIF
      DOEVENTS && we must check for the State
      THISFORM.stStatusBar.panels(1).text = THISFORM.ConnState()
      *... and show it on the form
      IF .state = 9
         .OBJECT.CLOSE()
         RETURN
      ENDIF
      IF SECONDS() - ntime > 5
         THISFORM.stStatusBar.panels(1).text = 'Connect fail:Timeout'
         EXIT
      ENDIF
   ENDDO
   THISFORM.txtLocalPort.VALUE = .localPort
   
ENDWITH

THIS.ENABLED = .F.
THISFORM.cmdClose.ENABLED     = .T.
ThisForm.cmdConnect.Enabled   = .F.
THISFORM.cmdSend.ENABLED      = .T.

thisform.Refresh()
RETURN



-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Just to clarify, the key component I changed is the following line:
Code:
IF "Visual FoxPro 07" $ VERSION()
It now reads:
Code:
IF !('Visual FoxPro 06' $ VERSION())
I have also added a 'timeout' so it doesn't hang on bad connections as easy.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Thank you! I will try your modified later today hopefully...

Trey
 
SO! This is how busy I've been lately: just now getting a chance to get back on this.

I replaced the cmdConnect.Click code with what you posted and it seems to connect to a server running Telnet here on my test LAN. Status bar says Status:Connected/Sent.

Can you suggest any test commands to send to the telnet server via your form to see if it is truly sending? (I'm admitting my ignorance of telnet here.) Also how can I change the responses in the window to be readable? Would this be a "term" command?

My ultimate goal is to send a set of commands to a digital signage appliance that is probably Linux-based, I'm guessing (it's a black box) after establishing a telnet connection to it. Problem today is that that signage device is not here. Just FYI.

And thanks for the help, Dave.
 
Well, it depends on what your telnet server is expecting. Usually it wants a login of some sort though.
If nothing else, typing a wrong command should return an error.
Are you getting anything returned in the box?


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
After I tried a third server, I saw that your code was working beautifully. I think the problem was the first two servers I tried to connect to were "goofy". Then I was satisfied and perused your code and was educated as to how the winsock object works. Thank you, Dave, for showing me this new tool I have now! A star to you, kind sir!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top