server_open -- open TCP/IP connection to server on specified port


server_open [option] host service


Opens a TCP/IP connection to a server of host on the port specified by service. The server is then accessed using the standard Tcl file I/O commands. host may be a host name or an IP address. port may be a port number of a service name. option is one of -buf or -nobuf. If no options are specified, -buf is the default.

If -buf is specified, then the file is buffered. In this case, a pair of Tcl file ids are returned in a list. The first id is open for read access, the second for write. When writing to the file, the flush command must be used to force data in the buffer to be sent to the server. The close command must be called against both file ids when through with the socket. Buffered access will result in significantly better performance when reading data and will also improve a series of writes being done without intermixed reads. The fcntl command may be used to make one of these files unbuffered.

If -nobuf is specified, then the file is unbuffered and a single file id, open for both reading and writing, is returned.

If a host name is supplied and more than one address is valid for the host, the addresses are tried iteratively until a connection is established. Use server_info(TCLX) to obtain the list of valid addresses.