Sending ctrl-d through a socket

S

Scott

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(socketDescriptor, ptr, size);
 
G

Gianni Mariani

Scott wrote:
....
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';

const char ch='\004';
ptr=&ch[0];
size=1;
nwritten = write(socketDescriptor, ptr, size);

nwritten = write(socketDescriptor, &ch, size);

Maybe ?
 
K

Karl Heinz Buchegger

Scott said:
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';

those are 2 characters. '^' followed by the character 'D'
ptr=&ch[0];
size=1;
nwritten = write(socketDescriptor, ptr, size);

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
....
 
K

Kevin Goodsell

klaas said:
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_however_your_interface_is << EOF << flush;

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

-Kevin
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top