Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Telnet Connection: Example Script Using WinSock Internet Extender

Keywords: telnet winsock wwwsk34I.dll 

This sample script assumes a particular kind of telnet and login account. You will have to customize this to get it to work in your particular situation. If it isn't working, the reason could be that it is waiting for some kind of command line prompt, like > and getting something else instead ... like $.

Basically the telnet script is mostly responding WON'T and DON'T to any init sequences it receives.


acct="elmer"
pswd="d48ls12W"
oline=""
BoxOpen("Telnet","Initializing")
WinZoom("")
AddExtender("wwwsk34I.dll")

;Telnet Connect

socket = SOpen ()
SConnect (socket, "www.windowware.com", "telnet")

waitfor="login:"
gosub wait
SSendLine(socket,acct)
oline=strcat(oline,line)
BoxText(oline)

waitfor="Password:"
gosub wait
SSendLine(socket,pswd)
oline=strcat(oline,line)
BoxText(oline)

waitfor="TERM"
gosub wait
TimeDelay(2)
SSendLine(socket,@CRLF)
oline=strcat(oline,line)
BoxText(oline)

waitfor=" > "
gosub wait
SSendLine(socket,"who")
oline=strcat(oline,line)
BoxText(oline)

waitfor=" > "
gosub wait
SSendLine(socket,"exit")
oline=strcat(oline,line)
BoxText(oline)

waitfor=num2char(10)   ; linefeed
gosub wait
oline=strcat(oline,line)
BoxText(oline)

Message("",oline)

SClose(socket)

exit



:wait
   line=""
   while 1
   
      iacchk=srecvnum(socket,1)
      if !iacchk 
         err=sGetLastErr()
         if err == @SOK then continue
         Message("Network Error",err)
         SClose(socket)
         exit
      endif
             
      switch iacchk
         case 255
           command=sRecvNum(socket,1)
           if command>250 && command<255
                 option=sRecvNum(socket,1)
                 if option
                      SSendString(socket,strcat(num2char(255),num2char(252),num2char(option)))
                 endif
           endif
           if command==255 then  line=strcat(line,num2char(255))
           break
       
        case iacchk  ; other char
          line=strcat(line,num2char(iacchk))
          break
          
      endswitch
      
      BoxTitle(line)
      if strindex(line,waitfor,1,@fwdscan) then break
   end while
return


Article ID:   W12616
Filename:   Telnet Connection.txt