Sending ctrl-d through a socket

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott

    Sending ctrl-d through a socket

    I am using a TCPIP connection to communicate over port 23 (telnet) to
    a server,
    and I am having to mimic normal command line interface you owuld see
    in a telnet session (i.e. I have to write to this socket just like you
    would enter things on the keyboard if you telneted to this server).

    In a normal telnet session you can enter some commands which take a
    long time to complete, and they run in the background and you get the
    command line prompt back, you can hit <ctrl-d> on the keyboard to see
    the status of the background task and see if you get a response like
    "EXECUTED" or "WORKIGN", when you hit the <enter> again you will be
    back at the command line to continue working.

    Context is C++ on a Unix server:
    My problem is I cannot programatically mimic a <ctrl-d> input through
    the socket when required, so that I can read the background response.

    I have tried writing/sending all sort's of characters to emulate the
    keyboard sequence of ctrl-d. I am surprised that I cannot find
    anything in the usergroups related to this problem, perhaps control
    characters are most usually read but never sent?

    I have tried the following, but it did not work:
    const char ch='^D';
    ptr=&ch[0];
    size=1;
    nwritten = write(socketDes criptor, ptr, size);
  • Gianni Mariani

    #2
    Re: Sending ctrl-d through a socket

    Scott wrote:
    ....[color=blue]
    > I have tried writing/sending all sort's of characters to emulate the
    > keyboard sequence of ctrl-d. I am surprised that I cannot find
    > anything in the usergroups related to this problem, perhaps control
    > characters are most usually read but never sent?
    >
    > I have tried the following, but it did not work:
    > const char ch='^D';[/color]

    const char ch='\004';
    [color=blue]
    > ptr=&ch[0];
    > size=1;
    > nwritten = write(socketDes criptor, ptr, size);[/color]

    nwritten = write(socketDes criptor, &ch, size);

    Maybe ?

    Comment

    • Karl Heinz Buchegger

      #3
      Re: Sending ctrl-d through a socket



      Scott wrote:[color=blue]
      >
      > I am using a TCPIP connection to communicate over port 23 (telnet) to
      > a server,
      > and I am having to mimic normal command line interface you owuld see
      > in a telnet session (i.e. I have to write to this socket just like you
      > would enter things on the keyboard if you telneted to this server).
      >
      > In a normal telnet session you can enter some commands which take a
      > long time to complete, and they run in the background and you get the
      > command line prompt back, you can hit <ctrl-d> on the keyboard to see
      > the status of the background task and see if you get a response like
      > "EXECUTED" or "WORKIGN", when you hit the <enter> again you will be
      > back at the command line to continue working.
      >
      > Context is C++ on a Unix server:
      > My problem is I cannot programatically mimic a <ctrl-d> input through
      > the socket when required, so that I can read the background response.
      >
      > I have tried writing/sending all sort's of characters to emulate the
      > keyboard sequence of ctrl-d. I am surprised that I cannot find
      > anything in the usergroups related to this problem, perhaps control
      > characters are most usually read but never sent?
      >
      > I have tried the following, but it did not work:
      > const char ch='^D';[/color]

      those are 2 characters. '^' followed by the character 'D'
      [color=blue]
      > ptr=&ch[0];
      > size=1;
      > nwritten = write(socketDes criptor, ptr, size);[/color]

      you need to send the character code for your system
      On an ASCII system that would be

      const char ch = 0x04;

      ctrl a -> 0x01
      ctrl b -> 0x02
      ctrl c -> 0x03
      ....

      --
      Karl Heinz Buchegger
      kbuchegg@gascad .at

      Comment

      • White Wolf

        #4
        Re: Sending ctrl-d through a socket

        klaas wrote:
        [SNIP][color=blue]
        > use EOF, it's a sumbolis integer constant defined in <iostream>,[/color]
        [SNIP]

        sumbolis as symbolic?

        --
        WW aka Attila


        Comment

        • Kevin Goodsell

          #5
          Re: Sending ctrl-d through a socket

          klaas wrote:
          [color=blue]
          >[color=green]
          >> My problem is I cannot programatically mimic a <ctrl-d> input through
          >> the socket when required, so that I can read the background response.
          >>
          >> I have tried writing/sending all sort's of characters to emulate the
          >> keyboard sequence of ctrl-d.[/color]
          >
          > control-d on unix means end-of-file
          > on windows this would be control-z
          >
          > if you want it, you can use
          > #include <iostream>
          >
          > using std::flush;
          >
          > socket_or_howev er_your_interfa ce_is << EOF << flush;[/color]

          This has basically no chance of working. EOF is an integer. This will
          print a string representation of it's value. Try it.

          -Kevin
          --
          My email address is valid, but changes periodically.
          To contact me please use the address from a recent posting.

          Comment

          Working...