Home |
Function accept |
Function acceptAccept a connection from any remote host; TCP only. SOCKET accept(SOCKET socket, struct sockaddr * addr, int * addrlen); ParameterssocketSocket returned by socket, bound by bind and previously placed in listen state by listen. addrOptionally returns the IP address and port number of the host connected to this socket; the port number and IP address are in network byte order. This parameter has type struct sockaddr * for historical reasons. Use type struct sockaddr_in * instead. The parameter may be NULL. addrlenPointer to length of valid information in *addr. If parameter addr is NULL, this parameter is ignored and may also be NULL. return valueReturns a newly allocated socket assigned to this connection if successful, otherwise SOCKET_ERROR. If an error occurred, call xn_getlasterror and xn_geterror_string to return the error value. Error Codes further describes each error. Possible values for this function are:
This routine waits for an established connection initiated from a remote host on this socket. bind and listen must be called before accept. The function returns immediately if a connection has been established. If no connections have been established and the socket is in blocking mode, accept blocks until a connection has been established or an error is detected. If no connections have been established and the socket is non-blocking, accept returns immediately with an error. select may be called to determine when an established connection exists. The IP address and port number of the host that connected to this socket is stored in addr. The size of the structure is passed to accept in addrlen and the number of valid bytes in addr, set by accept, is returned in addrlen. accept returns a new socket to be used for the connection but the original socket is still allocated and needs to be closed when no more accept on the original socket will be done. The socket returned by accept also needs to be closed when it is no longer needed. This function is for TCP only. In blocking mode, this function blocks infinitely. Use select for a timeout capability. This function does not support sockets in secure mode. For secure sockets, use function net_accept instead.
|