Copyright (C) 2000-2012 |
Manpages socketSection: Tcl Built-In Commands (n)Updated: 8.0 Index Return to Main Contents NAMEsocket - Open a TCP network connectionSYNOPSISsocket ?options? host port socket -server command ?options? port DESCRIPTIONThis command opens a network socket and returns a channel identifier that may be used in future invocations of commands like read, puts and flush. At present only the TCP network protocol is supported; future releases may include support for additional protocols. The socket command may be used to open either the client or server side of a connection, depending on whether the -server switch is specified. CLIENT SOCKETSIf the -server option 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 www.sunlabs.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. The following options may also be present before host to specify additional information about the connection:
SERVER SOCKETSIf the -server option is specified then the new socket will be a server for the port given by port. Tcl will automatically accept connections to the given port. For each connection Tcl will create a new channel that may be used to communicate with the client. Tcl then invokes command with three additional arguments: the name of the new channel, the address, in network address notation, of the client's host, and the client's port number. The following additional option may also be specified before 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. Server sockets depend on the Tcl event mechanism to find out when new connections are opened. If the application doesn't enter the event loop, for example by invoking the vwait command or calling the C procedure Tcl_DoOneEvent, then no connections will be accepted. CONFIGURATION OPTIONSThe fconfigure command can be used to query several readonly configuration options for socket channels:
SEE ALSOflush(n), open(n), read(n)KEYWORDSbind, channel, connection, domain name, host, network address, socket, tcp
IndexThis document was created by man2html, using the manual pages. Time: 20:15:22 GMT, April 28, 2024 |