Manual Pages for UNIX Darwin command on man Tcl_MakeTcpClientChannel
MyWebUniversity

Manual Pages for UNIX Darwin command on man Tcl_MakeTcpClientChannel

TclOpenTcpClient(3) Tcl Library Procedures TclOpenTcpClient(3)

NAME

TclOpenTcpClient, TclMakeTcpClientChannel, TclOpenTcpServer - proce-

dures to open channels using TCP sockets

SYNOPSIS

##iinncclluuddee <>

TclChannel TTccllOOppeennTTccppCClliieenntt(interp, port, host, myaddr, myport, async) TclChannel TTccllMMaakkeeTTccppCClliieennttCChhaannnneell(sock) TclChannel TTccllOOppeennTTccppSSeerrvveerr(interp, port, myaddr, proc, clientData) AARRGGUUMMEENNTTSS TclInterp *interp (in) Tcl interpreter to use for error reporting. If

non-NULL and an error

occurs, an error message

is left in the inter-

preter's result. int port (in) A port number to connect to as a client or to listen on as a server. CONST char *host (in) A string specifying a host name or address for the remote end of the connection. int myport (in) A port number for the client's end of the socket. If 0, a port number is allocated at random. CONST char *myaddr (in) A string specifying the host name or address for network interface to use for the local end of the connection. If NULL, a default interface is chosen. int async (in) If nonzero, the client socket is connected asynchronously to the server.

ClientData sock (in) Platform-specific handle

for client TCP socket. TclTcpAcceptProc *proc (in) Pointer to a procedure to invoke each time a new connection is accepted via the socket.

ClientData clientData (in) Arbitrary one-word value

to pass to proc.

DESCRIPTION

These functions are convenience procedures for creating channels that communicate over TCP sockets. The operations on a channel are described in the manual entry for TTccllOOppeennFFiilleeCChhaannnneell. TTCCLLOOPPEENNTTCCPPCCLLIIEENNTT TTccllOOppeennTTccppCClliieenntt opens a client TCP socket connected to a port on a specific host, and returns a channel that can be used to communicate with the server. The host to connect to can be specified either as a

domain name style name (e.g. wwwwww..ssuunnllaabbss..ccoomm), or as a string contain-

ing the alphanumeric representation of its four-byte address (e.g.

112277..00..00..11). Use the string llooccaallhhoosstt to connect to a TCP socket on the host on which the function is invoked. The myaddr and myport arguments allow a client to specify an address

for the local end of the connection. If myaddr is NULL, then an inter-

face is chosen automatically by the operating system. If myport is 0, then a port number is chosen at random by the operating system. If async is zero, the call to TTccllOOppeennTTccppCClliieenntt returns only after the client socket has either successfully connected to the server, or the attempted connection has failed. If async is nonzero the socket is

connected asynchronously and the returned channel may not yet be con-

nected to the server when the call to TTccllOOppeennTTccppCClliieenntt returns. If the channel is in blocking mode and an input or output operation is done on the channel before the connection is completed or fails, that operation will wait until the connection either completes successfully or fails. If the channel is in nonblocking mode, the input or output operation will return immediately and a subsequent call to TTccllIInnppuuttBBlloocckkeedd on the channel will return nonzero. The returned channel is opened for reading and writing. If an error occurs in opening the socket, TTccllOOppeennTTccppCClliieenntt returns NULL and records a POSIX error code that can be retrieved with TTccllGGeettEErrrrnnoo. In

addition, if interp is non-NULL, an error message is left in the inter-

preter's result.

The newly created channel is not registered in the supplied inter-

preter; to register it, use TTccllRReeggiisstteerrCChhaannnneell. If one of the stan-

dard channels, ssttddiinn,, ssttddoouutt or ssttddeerrrr was previously closed, the act of creating the new channel also assigns it as a replacement for the standard channel. TTCCLLMMAAKKEETTCCPPCCLLIIEENNTTCCHHAANNNNEELL TTccllMMaakkeeTTccppCClliieennttCChhaannnneell creates a TTccllCChhaannnneell around an existing, platform specific, handle for a client TCP socket.

The newly created channel is not registered in the supplied inter-

preter; to register it, use TTccllRReeggiisstteerrCChhaannnneell. If one of the stan-

dard channels, ssttddiinn,, ssttddoouutt or ssttddeerrrr was previously closed, the act of creating the new channel also assigns it as a replacement for the standard channel. TTCCLLOOPPEENNTTCCPPSSEERRVVEERR TTccllOOppeennTTccppSSeerrvveerr opens a TCP socket on the local host on a specified port and uses the Tcl event mechanism to accept requests from clients to connect to it. The myaddr argument specifies the network interface. If myaddr is NULL the special address INADDRANY should be used to

allow connections from any network interface. Each time a client con-

nects to this socket, Tcl creates a channel for the new connection and invokes proc with information about the channel. Proc must match the following prototype: typedef void TclTcpAcceptProc( ClientData clientData, TclChannel channel, char *hostName, int port); The clientData argument will be the same as the clientData argument to TTccllOOppeennTTccppSSeerrvveerr, channel will be the handle for the new channel,

hostName points to a string containing the name of the client host mak-

ing the connection, and port will contain the client's port number. The new channel is opened for both input and output. If proc raises an error, the connection is closed automatically. Proc has no return value, but if it wishes to reject the connection it can close channel. TTccllOOppeennTTccppSSeerrvveerr normally returns a pointer to a channel representing the server socket. If an error occurs, TTccllOOppeennTTccppSSeerrvveerr returns NULL and records a POSIX error code that can be retrieved with TTccllGGeettEErrrrnnoo.

In addition, if the interpreter is non-NULL, an error message is left

in the interpreter's result. The channel returned by TTccllOOppeennTTccppSSeerrvveerr cannot be used for either input or output. It is simply a handle for the socket used to accept connections. The caller can close the channel to shut down the server and disallow further connections from new clients.

TCP server channels operate correctly only in applications that dis-

patch events through TTccllDDooOOnneeEEvveenntt or through Tcl commands such as vvwwaaiitt; otherwise Tcl will never notice that a connection request from a remote client is pending.

The newly created channel is not registered in the supplied inter-

preter; to register it, use TTccllRReeggiisstteerrCChhaannnneell. If one of the stan-

dard channels, ssttddiinn,, ssttddoouutt or ssttddeerrrr was previously closed, the act of creating the new channel also assigns it as a replacement for the standard channel. PPLLAATTFFOORRMM IISSSSUUEESS | On Unix platforms, the socket handle is a Unix file descriptor as | returned by the ssoocckkeett system call. On the Windows platform, the |

socket handle is a SSOOCCKKEETT as defined in the WinSock API. On the Macin- |

tosh platform, the socket handle is a SSttrreeaammPPttrr.

SEE ALSO

TclOpenFileChannel(3), TclRegisterChannel(3), vwait(n) KKEEYYWWOORRDDSS client, server, TCP Tcl 8.0 TclOpenTcpClient(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™