• Post Reply Bookmark Topic Watch Topic
  • New Topic

Multiplatform Telnet Server  RSS feed

 
Tristan McHardie
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This post should probably be in the Sockets forum as well...

I'm writing a server that will need to run on both Windows and Linux machines, with clients from both platforms as well. The clients use the standard Microsoft and GNU telnet clients.

The server waits for incoming connections and creates new sockets in the standard way, i.e.



I'm just confused as to which buffers/readers/writers I should be using on top of the socket's input and output streams to read/write lines of text to/from the clients.

I've tried a few approaches, but when the Microsoft client works well, the GNU client appends ^M each time I press Enter. I know this has something to do with MS using \n\r where *nix uses plain old \n, but how do I work around this in my server?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Telnet standard requires that both server and client send the two characters "CR" (^M) and "LF" (^J) at the end of each line, in that order. You have to write your server to send them, and also to expect them. If you don't expect them, you can easily end up in a situation where they get treated as part of the text data and you end up displaying them.

If you use BufferedReader.readLine() to read a line of input from the client, then the input part should be taken care of automatically. For output, though, you're going to have to explicitly write the characters you're supposed to send.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!