#include "uici.h" #include "chat.h" int main(int argc, char *argv[]){ u_port_t portnumber; int listenfd; int communfd; int i; char remote[MAX_CANON]; pthread_t thread[2]; void * (*pmain[2])(void *) = {reader, writer}; if (argc != 2) { fprintf(stderr, "Usage: %s port\n", argv[0]); exit(EXIT_FAILURE); } portnumber = (u_port_t)atoi(argv[1]); if ((listenfd = u_open(portnumber)) < 0) { u_error("Unable to establish a port connection"); exit(EXIT_FAILURE); } fprintf(stderr, "Server listening on port %d\n", portnumber); if ((communfd = u_listen(listenfd, remote)) < 0) { u_error("Failure to listen on server"); exit(EXIT_FAILURE); } fprintf(stderr, "Connection has been made to %s\n", remote); for(i = 0; i < 2; i++) if(pthread_create(&thread[i],NULL,pmain[i],&communfd) != 0){ fprintf(stderr, "Thread creation failed in server\n"); exit(EXIT_FAILURE); } for(i = 0; i < 2; i++) pthread_join(thread[i],NULL); u_close(listenfd); u_close(communfd); exit(EXIT_SUCCESS); }