Telnet and EOF with SocketChannel.read()

Discussion in 'Java' started by Fritz Bayer, Dec 8, 2004.

  1. Fritz Bayer

    Fritz Bayer Guest

    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
     
    Fritz Bayer, Dec 8, 2004
    #1
    1. Advertising

  2. On 8 Dec 2004 03:11:28 -0800, Fritz Bayer wrote:
    > 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

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Dec 8, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fritz Bayer
    Replies:
    16
    Views:
    11,143
    Esmond Pitt
    Jul 27, 2004
  2. ATC
    Replies:
    3
    Views:
    3,391
    Steve Horsley
    Sep 11, 2004
  3. Jim Isaacson
    Replies:
    5
    Views:
    629
    Default User
    Nov 5, 2004
  4. Kobu
    Replies:
    10
    Views:
    674
    Keith Thompson
    Mar 4, 2005
  5. Carcarius
    Replies:
    0
    Views:
    331
    Carcarius
    Dec 6, 2007
Loading...

Share This Page