httpserver/sockets.cpp
//--------------------------------------------------------------------------------------------
// This function will create HTTP listen socket (usually at port 80) to process all HTTP
// requests
//--------------------------------------------------------------------------------------------
This function will create HTTP listen socket (usually at port 80) to process all HTTP
requests
This function will create HTTP listen socket ( usually at port 80 ) to process all HTTP requests
int CreateListener(int port) {
    int sock;
    struct sockaddr_in name;
    sock = socket (PF_INET, SOCK_STREAM, 0);
    if (sock < 0) return -1;
    unsigned int set_option = 1;
    setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&set_option, sizeof(set_option));
    name.sin_family      = AF_INET;
    name.sin_port        = htons(port);
    name.sin_addr.s_addr = htonl(INADDR_ANY);
    if (bind (sock, (struct sockaddr *) &name, sizeof (name)) < 0)
	    return -1;
    if(listen(sock, 5) < 0)
	   return -1;
	return sock;
}
int CreateListener ( int port ) { int sock ; struct sockaddr_in name ; sock = socket ( PF_INET , SOCK_STREAM , 0 ) ; if ( sock < 0 ) return -1 ; unsigned int set_option = 1 ; setsockopt ( sock , SOL_SOCKET , SO_REUSEADDR , ( const char * ) & set_option , sizeof ( set_option ) ) ; name . sin_family = AF_INET ; name . sin_port = htons ( port ) ; name . sin_addr . s_addr = htonl ( INADDR_ANY ) ; if ( bind ( sock , ( struct sockaddr * ) & name , sizeof ( name ) ) < 0 ) return -1 ; if ( listen ( sock , 5 ) < 0 ) return -1 ; return sock ; }
This function will create HTTP listen socket (usually at port 80) to process all HTTP
requests
This function will create HTTP listen socket ( usually at port 80 ) to process all HTTP requests
/* Create the socket. */ /* Give the socket a name. */