I am writing a Telnet server in Java and am finding it difficult to handle the initial client (using PuTTY in this case) options:
The Telnet protocol states that first, the client sends the server 3-byte codes beginning with 255 which state the Telnet options. Hence, I first read the bytes sent in using the BufferedReader's read() method (which returns an integer). I then convert the second byte of each 3-byte code to disable the option in the manner stated in this thread. My response is then sent. However, the client doesn't respond back with more options until I send it yet another stream of data. (Its response in my case being: 255 251 36.) It doesn't seem to matter what I send, it will always response with that code.
Why is the client doing this? Is it a bug in PuTTY - not flushing the output stream? Is initialising a Telnet communication a 2 part process? How can I handle this?
I'm uncomfortable with you using character streams for binary data such as 255 251 36 since character conversion issues may mean you are not actually sending what you think you are. I would expect you to be using byte streams.
P.S. Do you really think that a well tested and universally used product like Putty is likely to have such a fundamental bug?
subject: Initialising the Telnet options with the client