socket 3plumb 2012-08-12

NAME

socket - networking

SYNPOSIS

[socket proto=tcp4-connect host=repo.hu port=80 reconn=3]

                    3
                (control)
                    |
                    V
               +---------+
0 (stdin) ---->| socket  |----> (stdout) 1
               +---------+
                 |     |
                 V     V
          (stderr)     (events)
                 2     4

DESCRIPTION

socket creates a network socket. Once the socket is connected, it reads its stdin relaying messages to a network socket and reads the network socket and relaying messages to its stdout. When the socket is closed (or can not be open), an event is generated. If any message is received on stdin when the socket is not connected, the message is discarded and an event is generated. Events are also generated when the socket is open or closed.

When reconn=single, a single connection is made when the virtual process starts and if that conneciton is broken, the virtual process quits. In any other case, the virtual process is persistent even if the socket connection is lost. If reconn=idle, no initial connection is made on start or after losing the connection, the process is waiting for commands on the control fd to initiate a connection. If reconn is a positive integer, the initial connection is made immediately at start and if the connection is lost, a reconnect is attempted after reconn seconds.

eof handling

EOF received on stdin will close the socket. EOF received on the socket will be propagated back to stdin.

blocking/flow control

Block on stdout will block socket reading which will eventually makes socket buffers fill up and the connection broken.

buffering

None.

EXAMPLE

# "netcat -l": listen on port 7000, relay data between the socket and
# stdio plus print events on stderr
include stdio
stdin:* | serv=[socket proto=tcp4-listen host=127.0.0.1 port=7000] | stdout:*
serv:2 | stderr:*
serv:4 | stderr:*

SEE ALSO

socket 3plumb 2012-08-12