PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → WD20 - write a telnet client
WD20 - write a telnet client
Iniciado por guest, 27,may. 2016 16:22 - 2 respuestas
Publicado el 27,mayo 2016 - 16:22
Hi,

one of mhy clients uses weight eqiuipment which sends data to a telnet client. There it's written to a ascii file for further use.

Can I write a simple Telnet client in Windev too? Is it just a matter of listening on tcpip port 23 and capture all incoming data?
Publicado el 28,mayo 2016 - 09:49
Hi Arie,

Years ago I made a little program (WD15 ) that manages playlists on a Linux device using Telnet.
Perhaps this code is useful to you:

PROCEDURE Telnet_Open_List() sFile,sReturn,sIP,sPlayListInternal is string x,sCommandstring is string nPort is int sIP=INIRead("Net","IP","",sIniName) nPort=INIRead("Net","TelnetPort","23",sIniName) sPlayListInternal=INIRead("Net","Playlist_internal","usr/local/etc/dvdplayer/playlist",sIniName) WHEN EXCEPTION IN sFile=fTempFile("tmp",sCurrentRootDir) DO Error("Kan geen tijdelijk bestand aanmaken op "+sCurrentRootDir,"Controleer of de Mediaplayer is verbonden en ingeschakeld.") RETURN END IF sFile="" THEN Error("Kan geen tijdelijk bestand aanmaken op "+sCurrentRootDir) RETURN END IF NOT SocketExist("TelNet") THEN IF NOT SocketConnect("TelNet",nPort,sIP) THEN Error("Fout bij verbinding met "+sIP+":"+nPort+CR+ErrorInfo()) HourGlass(False) RETURN END END SocketChangeTransmissionMode("TelNet",SocketNoEndTag) sReturn=DataHandler() //Login IF sReturn="TIMEOUT" THEN Error("Timeout bij login") RETURN END SocketWrite("TelNet","root"+ CR) sReturn=DataHandler() //welcome and prompt x=sLocalDir+fExtractPath(sFile,fFileName+fExtension) x=Replace(x,"\","/") sCommandstring="cp "+sPlayListInternal+" "+x SocketWrite("TelNet",sCommandstring+CR) sReturn=DataHandler() //Prompt SocketWrite("TelNet","exit"+CR) SocketClose("TelNet") IF NOT ReadPlayList(sFile,Charact(0)) THEN Error("Kan tijdelijk bestand niet lezen "+sFile) RETURN END IF NOT fDelete(sFile) THEN Error(StringBuild("Kan tijdelijk bestand %1 niet verwijderen. ",sFile)) END PROCEDURE DataHandler(nTimeOut=10000) //10 seconden timeout b,n,nState,nNow is int x,sData,sResult,sDate is string bConfirm is boolean nNow=TimeToInteger(TimeSys()) sDate=DateSys() LOOP IF sDate<>DateSys() THEN nNow-=8640000 //24*60*60*100 END IF TimeToInteger(TimeSys())-nNow>nTimeOut THEN RESULT "TIMEOUT" Multitask(-1) sData=SocketRead("TelNet",False) IF sData="" THEN BREAK // Loop through each available byte returned from the socket connection. FOR n=1 _TO_ Length((sData)) // Read next available byte. x=sData[[n]] b=Asc(x) SWITCH nState CASE 0 // If the current byte is the "Interpret as Command" code, set the state to 1. IF b=tn_IAC THEN nState = 1 ELSE sResult+=x END CASE 1 // If the current byte is the "DO" code, set the state to 2. IF b=tn_DO THEN nState=2 bConfirm=True ELSE IF b=tn_WILL THEN nState=2 bConfirm=False ELSE nState=0 // Blindly reject the option. END CASE 2 //Write the "Interpret as Command" code, "WONT" code, //and current byte to the socket and send the contents //to the server by calling the flush() method. IF bConfirm THEN SocketWrite("TelNet",Charact(tn_IAC)+Charact(tn_WONT)+Charact(b)) nState = 0 END END END RESULT sResult
Best regards,
Piet
Publicado el 28,mayo 2016 - 15:19
Great thanks!