gochatai/pachi_py/pachi/network.c
/* Create a socket, bind to it on the given port and listen.
 * This function is restricted to server mode (port has
 * no hostname). Returns the socket. */
Create a socket, bind to it on the given port and listen.
This function is restricted to server mode (port has
no hostname). Returns the socket.
Create a socket bind to it on the given port and listen . This function is restricted to server mode ( port has no hostname ) . Returns the socket .
int
port_listen(char *port, int max_connections)
{
	int sock = socket(AF_INET, SOCK_STREAM, 0);
	if (sock == -1)
		die("socket");
	struct sockaddr_in server_addr;
	memset(&server_addr, 0, sizeof(server_addr));
	server_addr.sin_family = AF_INET;         
	server_addr.sin_port = htons(atoi(port));     
	server_addr.sin_addr.s_addr = INADDR_ANY; 
	const char val = 1;
	if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)))
		die("setsockopt");
	if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr)) == -1)
		die("bind");
	if (listen(sock, max_connections) == -1)
		die("listen");
	return sock;
}
int port_listen ( char * port , int max_connections ) { int sock = socket ( AF_INET , SOCK_STREAM , 0 ) ; if ( sock == -1 ) die ( " " ) ; struct sockaddr_in server_addr ; memset ( & server_addr , 0 , sizeof ( server_addr ) ) ; server_addr . sin_family = AF_INET ; server_addr . sin_port = htons ( atoi ( port ) ) ; server_addr . sin_addr . s_addr = INADDR_ANY ; const char val = 1 ; if ( setsockopt ( sock , SOL_SOCKET , SO_REUSEADDR , & val , sizeof ( val ) ) ) die ( " " ) ; if ( bind ( sock , ( struct sockaddr * ) & server_addr , sizeof ( struct sockaddr ) ) == -1 ) die ( " " ) ; if ( listen ( sock , max_connections ) == -1 ) die ( " " ) ; return sock ; }
Create a socket, bind to it on the given port and listen.
Create a socket bind to it on the given port and listen .