By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,122 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,122 IT Pros & Developers. It's quick & easy.

Sending ctrl-d through a socket

P: n/a
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);
Jul 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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 ?

Jul 19 '05 #2

P: n/a


Scott wrote:

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

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #3

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

[SNIP]

sumbolis as symbolic?

--
WW aka Attila
Jul 19 '05 #4

P: n/a
klaas wrote:
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.


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
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

Jul 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.