NAME
       socket - Open a network connection

SYNOPSIS
       socket ?protocol? host port

       socket -server command ?protocol? port


DESCRIPTION
       This  command opens a network socket and returns a channel
       identifier that may be used in future invocations of  com-
       mands  like  read, puts and flush.  The socket command may
       be used to open either the client or server side of a con-
       nection, depending on whether the -server switch is speci-
       fied.

       If -server is not specified, then the  client  side  of  a
       connection  is  opened  and  the command returns a channel
       identifier that can be used for both reading and  writing.
       Port and host specify a port to connect to;  there must be
       a server accepting connections on this port.  Port  is  an
       integer port number and host is either a domain-style name
       such as noam.eng.sun.com or a numerical IP address such as
       127.0.0.1.   Use  localhost  to refer to the host on which
       the command is invoked.  If a protocol  option  is  speci-
       fied,  it  indicates which protocol to use when connecting
       to the server.  At present, the only valid option for pro-
       tocol  is -tcp, which selects the TCP protocol.  If proto-
       col is omitted it defaults to -tcp.

       If the -server option is specified then  this  application
       becomes a server for the port given by port.  Tcl automat-
       ically accepts connections from clients on the given port.
       For  each connection Tcl creates a new channel that may be
       used to communicate with the  client.   Tcl  then  invokes
       command with two additional arguments: the name of the new
       channel and the address, in network address  notation,  of
       the client's host.

       Server  channels cannot be used for input or output; their
       sole use is to accept new client connections. The channels
       created for each incoming client connection are opened for
       input and output. Closing the server  channel  shuts  down
       the  server  so  that no new connections will be accepted;
       however, existing connections will be unaffected.


SEE ALSO
       flush(n), open(n), read(n)


KEYWORDS
       channel, connection, domain name, host,  network  address,
       socket, tcp
