int main(int argc, char *argv[]) { int clntSock; struct sockaddr_in cli_addr; pthread_t threadID; /* Thread ID from pthread_create() */ struct ThreadArgs *threadArgs; /* Pointer to argument structure for thread */ unsigned int clntLen; /* Length of client address data structure */ clntLen = sizeof(cli_addr); servSock = createTCPServerSocket(PORT); while(1) { clntSock = acceptTCPConnection(servSock); getpeername(clntSock, (struct sockaddr *) &cli_addr, &clntLen); /* Create separate memory for client argument */ if ((threadArgs = (struct ThreadArgs *) malloc(sizeof(struct ThreadArgs))) == NULL) error("malloc() failed"); threadArgs -> clntSock = clntSock; threadArgs -> addr = inet_ntoa(cli_addr.sin_addr); if (pthread_create(&threadID, NULL, handleThreadClient, (void *) threadArgs) != 0) error("pthread_create() failed"); // printf("\n+ New client[%d][Addr:%s]\n\n", // clntSock, inet_ntoa(cli_addr.sin_addr)); } close(servSock); return 0; }
* Success|------------------------------------- | * Failure|---------------------------------------- */ const char* StateName[] = { "STOP", "WAITING CONNECT", "PLAYING AND WAITING MAINPLAYER", "PLAYING AND WAITING NEW QUESTION", "PLAYING AND WAITING QUESTION COMPLETE", "PLAYING AND WAITING USERANSWER" }; void init(Server *new, Monitor *monitor,ServerManager *manager, Question question) { new -> serverSock = createTCPServerSocket(NULL); new -> currentQuestion = question; new -> monitor = monitor; new -> manager = manager; new -> run = run; new -> requestProcessing = requestProcessing; new -> commandProcessing = commandProcessing; new -> disconnect = disconnect; new -> viewStatus = viewStatus; (new -> monitor) -> addFD(new -> monitor, 0); (new -> monitor) -> addFD(new -> monitor,new -> serverSock); //n_player_answer <= n_fetch_question_complete <= n_player_accept <= n_player < n_ready <= n_connect new -> db =createDbAction("game_question.db"); char *zERR; new -> db . assignStatement(&new -> db,LOGIN_STATEMENT); int erroCode = sqlite3_prepare_v2((new -> db) . dbObj , LOGIN_STATEMENT,100,&new -> loginStatement,&zERR);