// vim: ts=2 sw=2 et #include #include #include #include #include #include #include "morpion.h" #include "socket.h" int server(unsigned short int port); int main(int argc, char **argv) { unsigned short int port; if (argc != 2) { printf("server only accepts one PORT argument.\n"); return EXIT_FAILURE; } port = atoi(argv[1]); if (port < 1) { printf("PORT must be a positive integer.\n" "PORT must be > 1024 if you're not root.\n"); return EXIT_FAILURE; } return server(port); } int client_input(int file_descriptor, char board[9]); int server(unsigned short int port) { // TODO Open server socket here (use socket.c) // TODO Wait for first client here (use accept) // TODO Wait for second client here (use accept) // TODO Close server socket (use close) char winner = ' '; char board[9] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; char current_player = 'O'; int current_player_socket, waiting_player_socket; while (winner == ' ') { // TODO toggle current_player, current_player_socket, waiting_player_socket; if (current_player == 'X') { // ... } else { // ... } // TODO Tell the waiting player that we wait for the current player to play // (use dprintf) // TODO Wait for client input (use client_input below) // TODO Send new board to both players (use morpion.c) // Update winner winner = get_winner(board); } // TODO Send appropriate messages according to the value of the winner // variable // TODO Close connections return EXIT_SUCCESS; } int client_input(int file_descriptor, char board[9]) { char input; int converted; do { // TODO Read user input (use read) // TODO Convert char to int (use - '0') // TODO change the while condition } while (1); return converted; }