how to start and close telnet sessions
Hello,
how can i close a telnet session from Netlinx?
I know that just sending a "send_string" to a serial port with a device with a telnet session on it will send the data to that device (if the serial parameters are well configured).
But i need to start a telnet session, send something, and the close it to be able to later start a new session with a different user, for example. How could i implement that? Something like "ip_client_open" and "ip_client_close".
Thank you!
how can i close a telnet session from Netlinx?
I know that just sending a "send_string" to a serial port with a device with a telnet session on it will send the data to that device (if the serial parameters are well configured).
But i need to start a telnet session, send something, and the close it to be able to later start a new session with a different user, for example. How could i implement that? Something like "ip_client_open" and "ip_client_close".
Thank you!
0
Comments
define_function fnPlayerSerial(char ccmd[100], integer ndevice) // Send Command to Serial port of Player { if(TPlayer[ndevice].nonline) { if(!ndvplayerSerialOnline[ndevice])IP_CLIENT_OPEN(dvplayerserial[ndevice].PORT,TPlayer[ndevice].cSourceIP,lPlayerControlPort,IP_TCP) timed_wait_until(ndvPlayerSerialOnline[ndevice])100 { send_string dvplayerserial[ndevice],"'GET /command?',ccmd,' HTTP/1.0',$0D,$0A,'Host: ',TPlayer[ndevice].cSourceIP,':',itoa(lPlayerControlPort),$0D,$0A,$0D,$0A" if (nDebug) send_string 0,"'GET /command?',ccmd,' HTTP/1.0',$0D,$0A,'Host: ',TPlayer[ndevice].cSourceIP,':',itoa(lPlayerControlPort),$0D,$0A,$0D,$0A" wait 100 ip_client_close(dvplayerserial[ndevice].PORT) } } }They way i done it, i open a telnet socket, send my command wait a time then i close it. it's very basic and it working great.
Yeah, I think Raphayo is confusing "telnet" with a TCP connection. His example is actually implementing HTTP. Telnet is different animal.
Yes your right it was not a telnet connection it was an http get command on a specific port. But using that kind of logic will give you the abilities to control your device thru telnet.
thanks for the answers, but in my post i was refering to a "serail port" connection, so no TCP socket connection is available (can't use ip_client_open / close).
Well, if it's just an rs232 connection, it's just simply mimicking whatever you do with a terminal session with a computer. Most times you have to send a CR/LF to wake the connection up. Then build a call/response routine to get through the login phase. You'll also have to figure out what character the terminal uses for a cursor and watch for that as well. A lot depends upon the behavior of the device..
DEFINE_FUNCTION fnDevMod_Online() ///clean { ////fnDevMod_DeBug("'ONLINE :DEBUG <',ITOA(__LINE__),'>'"); CANCEL_WAIT 'WAITING_TO_CONNECT'; sJAP.nConnectState = IP_CLIENT_CONNECTED; sJAP.nConnectAttempts = 0; ON[vdvDev,254]; if(!sJAP.nDev_Is_IP) { SEND_COMMAND dvDev,'SET BAUD 9600,N,8,1 485 DISABLE' SEND_COMMAND dvDev,"'HSOFF'" SEND_COMMAND dvDev,"'XOFF'" //fnDevMod_DeBug("'RS232 connection [',fnDEV_TO_STRING(dvDev),'] * DEVICE ONLINE :DEBUG <',ITOA(__LINE__),'>'"); //fnDevMod_DeBug("'Initialized Serial Port! :DEBUG <',ITOA(__LINE__),'>'"); } else { //fnDevMod_DeBug("'IP connection [',fnDEV_TO_STRING(dvDev),'] * DEVICE ONLINE :DEBUG <',ITOA(__LINE__),'>'"); if(sJAP.nErrCode == ERR_FORCE_RECON) { fnSend_Main_LVL(nNumSWPorts,ERR_RECON_OK); } } sJAP.nAccessLevel = LEVEL_ZERO; fnCTS(); fnQueue_Process_Q(); RETURN; }Your params may vary. Some devices also require login so that may come up and require an exchange to gain access and that access may time out so you may have to login again but most devices are simple and should only require to proper serial comm parameters be sent to the port.