Telnet Client Script for RunRev

Open a socket to the device, send a command and read from the same socket with a message, probably using lf, cr or crlf as line ending. Never close the socket, unless you want to log out.

Below follows a very simple example, which may work only in theory but which shows the basics of a telnet client.

// button script
on mouseUp
 put “” into myDevSock
 set the cSock of fld “Command” to myDevSock
 open socket myDevSock
 write “hello” to socket myDevSock // whatever command is appropriate
 read from socket myDevSock until cr with msg “gotReply”
end mouseUp

// card script
on preOpenCard
  set the cSock of fld “Command” to empty
end preOpenCard

// card script
on gotReply theSock,theMsg
 put theMsg into fld “Terminal”
 select text of fld “Command”
end gotReply

// card script
on closeStackRequest
  put the cSock of fld “Command” into myDevSock
  answer “Do you want to close the connection?” with “Yes” or “No”
  if it is “Yes” and myDevSock is not empty then
    close socket myDevSock
    pass closeStackRequest
  end if
end closeStackRequest

// field “Command”
on returnInField
 put the cSock of me into myDevSock
 write the text of me to socket myDevSock
 read from socket myDevSock until cr with msg “gotReply”
end returnInField

I haven’t tested this, but it should work.  You need a stack with a field “Terminal”, a field “Command” and a button. Put the scripts into their respective places and change the IP and port numbers. If necessary, change cr into crlf for example. You might need to escape some characters before sending them to the telnet server; check the documentation of the server.


Leave a Reply

Your email address will not be published. Required fields are marked *