SDLNet_TCP_Accept
Name
SDLNet_TCP_Accept -- Accept an incoming connection on the server TCPsocket.
Synopsis
TCPsocket SDLNet_TCP_Accept(TCPsocket server)
server This is the server TCPsocket which was previously created by SDLNet_TCP_Open.
Description
Accept an incoming connection on the server TCPsocket. Do not use this function on a connected socket. Server sockets are never connected to a remote host. What you get back is a new TCPsocket that is connected to the remote host. This is a non-blocking call, so if no connections are there to be accepted, you will get a NULL TCPsocket and the program will continue going.
Return Value
Returns: a valid TCPsocket on success, which indicates a successful connection has been established. NULL is returned on errors, such as when it's not able to create a socket, or it cannot finish connecting to the originating host and port. There also may not be a connection attempt in progress, so of course you cannot accept nothing, and you get a NULL in this case as well.
Example
To accept a connection coming in on server_tcpsock:
TCPsocket new_tcpsock;
new_tcpsock=SDLNet_TCP_Accept(server_tcpsock);
if(!new_tcpsock) {
printf("SDLNet_TCP_Accept: %s\n", SDLNet_GetError());
}
else {
// communicate over new_tcpsock
}
See Also
SDLNet_TCP_Open, SDLNet_TCP_GetPeerAddress, SDLNet_TCP_Close, TCPsocket
