This is a very primitive yet complete example of a telnet server written in RunRev. You can access it from the unix terminal with the command
telnet localhost 2222 It might work from the Windows command line as well, although you may have to replace “cr” with “numToChar(13) in the script below –just give it a try. After connecting, type something in the terminal and see what happens. Type “close” to close the connection.In RunRev, all you need is to create a button with the script below. Set the label of the button to “Start” or click the button twice when you run the server for the very first time.
on mouseUp
if the label of me is not “Start” then
closeAllSockets
set the label of me to “Start”
else
accept connections on port 2222 with message “welcome”
put the result into rslt
if rslt is not empty then
beep
answer error rslt
else
set the label of me to “Stop”
end if
end if
end mouseUp
write “Welcome. You are connected.” & cr & “rev> ” to socket theSock
read from socket theSock until cr with message “telnet”
end welcome on telnet theSock,theMsg
// uncomment next line if you want to see the message in a field
// put theMsg into fld 1
if theMsg begins with “close” then
write “byebye” & cr to socket theSock
close socket theSock
else
if theMsg begins with “beep” then beep
write “You wrote:” && theMsg & “rev> ” to socket theSock
read from socket theSock until cr with message “telnet”
end if
end telnet on closeAllSockets
put the openSockets into mySocks
repeat for each line mySock in mySocks
close socket mySock
end repeat
end closeAllSockets