Setting the user timeout in Linux is a bit tricky. I'd have to google for details myself.
The exit from telnet is simple, though. It's simply end-of-file. If you're running a telnet session from a script, the end of the stdin stream will disconnect. For interactive sessions, type Ctrl-D, just as you would to logout.
An IDE is no substitute for an Intelligent Developer.
Get me the mayor's office! I need to tell her about this tiny ad: