Re-directing stdin/out to socket.

Re-directing stdin/out to socket.

Post by Jim Godda » Sun, 26 Dec 1993 07:03:58



I am woking on a program that communicates via internet sockets.  I would
like to have this program spawn an editor.  My question is how do I
re-direct stdin/out to the socket or otherwise get the editor to
communicate via the socket?

Jim

 
 
 

Re-directing stdin/out to socket.

Post by Glenn Waldr » Tue, 28 Dec 1993 22:31:44


: I am woking on a program that communicates via internet sockets.  I would
: like to have this program spawn an editor.  My question is how do I
: re-direct stdin/out to the socket or otherwise get the editor to
: communicate via the socket?

: Jim

To redirect stdin to a socket:
close (0);
dup2 (sock, 0);         /* where sock is your socket. */

This works for 0=stdin, 1=stdout, or 2=stderr.

- Glenn.

 
 
 

Re-directing stdin/out to socket.

Post by Jim Vlc » Thu, 30 Dec 1993 09:27:26


Glenn Waldron writes


> : My question is how do I
> : re-direct stdin/out to the socket or otherwise get the editor to
> : communicate via the socket?

> To redirect stdin to a socket:
> close (0);
> dup2 (sock, 0);            /* where sock is your socket. */

> This works for 0=stdin, 1=stdout, or 2=stderr.

If your environment is POSIX-conformant, use:

#include <unistd.h>

close(STDIN_FILENO);
dup2(sock, STDIN_FILENO);

Ditto for STDOUT_FILENO and STDERR_FILENO.  If your environment is _not_  
POSIX-conformant, I recommend #defining these constants in a compatibility  
header somewhere and using them rather than the magic numbers 0, 1 and 2:

#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif /* STDIN_FILENO */

--
-----------------------------------------------------------------------------
Jim Vlcek                                         SVR4.2: A standard for UNIX
uunet!molly!vlcek                                 OpenStep: A standard for OO
Beautiful downtown St. Paul                       Windows: A standard for CYA

 
 
 

Re-directing stdin/out to socket.

Post by Sami-Jaakko Tik » Fri, 31 Dec 1993 06:44:37




> I am woking on a program that communicates via internet sockets.  I would
> like to have this program spawn an editor.  My question is how do I
> re-direct stdin/out to the socket or otherwise get the editor to
> communicate via the socket?

Others already answered the question of how to redirect.  There is however
a slight problem if you want to run any other editor but the most basic,
like ed.  Usually full-screen editors need access to a tty-device.  For
this purpose there are the pty-devices which you can use to run your editor
through.

The explanation is a bit long and difficult and I'm tired now.  If you
still need the info, mail me and I'll put together some instructions.  Also
tell me what unix flavour are you working with.

To demonstrate the problem I'm talking about, try doing an rlogin to a
remote host and then run an editor there.  Now disconnect and try to run
the editor on the remote system using rsh.  See what I mean?
--
<A HREF=http://www.cs.hut.fi/~sti/> My home page </A>
HUT/IIA; I don't speak for my employer.