IO.getc (Based off of #45 MUD)

Discussion in 'Ruby' started by Ari Brown, Jul 25, 2007.

  1. Ari Brown

    Ari Brown Guest

    I have some questions about sockets, IO.getc(), and IO.ready?().


    So my telnet server accepts
    connections. That works.
    It displays the
    prompt.
    That works.
    It accepts the single characters (IO.getc) without pressing return.
    That works.
    But wait! Whenever I connect to the server (telnet localhost), there
    is always this string of characters that are:

    ??%??&??&??^C?????? ??!??"??'????

    Where are those characters coming from, and is there a suitable
    workaround? I tried instituting a sleep 1 to allow the characters to
    pass (assuming it was a short stream), but they still came. I also
    noticed that this only happens when I press enter (which for me shows
    up a ^M. bwah?).

    CODE:
    loop do
    character = sock.getc
    if sock.ready?
    # puts sock.ready?
    # puts sock
    case character
    when ?\C-c
    print "^C"
    # break
    when ?\r, ?\n, ?\C-M
    $writer[$output_buffer]
    show_prompt
    else
    $output_buffer << character
    print character.chr
    end
    end

    I had to comment out 'break' so that I wouldn't get disconnected
    during the initial character stream.

    What's going on?

    Thanks,
    -------------------------------------------------------|
    ~ Ari
     
    Ari Brown, Jul 25, 2007
    #1
    1. Advertising

  2. On Jul 25, 2007, at 4:35 PM, Ari Brown wrote:

    > So my telnet server accepts
    > connections. That works.
    > It displays the
    > prompt.
    > That works.
    > It accepts the single characters (IO.getc) without pressing
    > return. That works.
    > But wait! Whenever I connect to the server (telnet localhost),
    > there is always this string of characters that are:
    >
    > ??%??&??&??^C?????? ??!??"??'????


    Those are telnet codes you will need to recognize and remove. Your
    client sends those to determine the features of the server. I
    discuss this a little and give code for it in this old quiz summary:

    http://rubyquiz.com/quiz32.html

    James Edward Gray II
     
    James Edward Gray II, Jul 26, 2007
    #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. Irrwahn Grausewitz

    Re: getc hanging

    Irrwahn Grausewitz, Aug 31, 2003, in forum: C Programming
    Replies:
    1
    Views:
    353
    Irrwahn Grausewitz
    Aug 31, 2003
  2. spike
    Replies:
    9
    Views:
    314
    Martien Verbruggen
    Feb 27, 2004
  3. PL

    detect Ctrl+C with getc ?

    PL, May 25, 2004, in forum: C Programming
    Replies:
    2
    Views:
    874
  4. William L. Bahn

    getc() vs. fgetc()

    William L. Bahn, Jul 14, 2004, in forum: C Programming
    Replies:
    13
    Views:
    1,799
    Dave Thompson
    Jul 21, 2004
  5. Bill Cunningham

    getc and ungetc

    Bill Cunningham, Nov 18, 2004, in forum: C Programming
    Replies:
    8
    Views:
    404
    Malcolm
    Nov 22, 2004
Loading...

Share This Page