Telnet and EOF with SocketChannel.read()

F

Fritz Bayer

Hello,

I'm playing around with the NIO api trying to figure out how certain
functions respond and work.

I know that SocketChannel.read() can return -1, which actually signals
a EOF. I have seen this and I'm trying to reproduce it

To do so I use telnet to connect to my server. Then I type "^]" so
enter the special mode of telnet and use "send eof" to sent an EOF to
the program.

I use a debugger to check out whats comming in. My
SocketChannel.read() returns two bytes -1 and -20 respectively. Those
correspond to the ISO 8859 latin1 of 255 and 236.

I was expecting that SocketChannel.read() would not fill the buffer
and return a -1 instead.

Now I was wondering if anybody has some suggestions on what I'm doing
wrong here?

I just thought that maybe the telnet program does not really send eof
but something else instead?

Typing in ^D does not work. This usually corresponds to EOF when using
bash under linux.

Fritz
 
G

Gordon Beaton

I'm playing around with the NIO api trying to figure out how certain
functions respond and work.

I know that SocketChannel.read() can return -1, which actually signals
a EOF. I have seen this and I'm trying to reproduce it

To do so I use telnet to connect to my server. Then I type "^]" so
enter the special mode of telnet and use "send eof" to sent an EOF
to the program.

"send eof" sends the "telnet end of file" character, which is a telnet
control character.

If you want the server to reach end of file, don't "send" anything.
You need to close the client connection. SocketChannel.read() will
indicate EOF at that point.
Typing in ^D does not work. This usually corresponds to EOF when
using bash under linux.

^D is not an EOF character either. It is a special character
interpreted by the console driver, telling it to close the input
stream to whatever process is reading from the current tty (and
thereby causing that process to detect EOF on its stdin).

/gordon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top