#include "uici.h" #include "chat.h" int main(int argc, char *argv[]){ u_port_t portnumber; pthread_t thread[2]; void * (*pmain[2])(void *) = {reader, writer}; int outfd; int i; if (argc != 3) { fprintf(stderr, "Usage: %s host port\n", argv[0]); exit(EXIT_FAILURE); } portnumber = (u_port_t)atoi(argv[2]); if ((outfd = u_connect(portnumber, argv[1])) < 0) { u_error("Unable to establish an Internet connection"); exit(EXIT_FAILURE); } fprintf(stderr, "Connection has been made to %s\n", argv[1]); for(i = 0; i < 2; i++) if(pthread_create(&thread[i],NULL,pmain[i],&outfd) != 0){ fprintf(stderr, "Thread creation failed in client\n"); exit(EXIT_FAILURE); } for(i = 0; i < 2; i++) pthread_join(thread[i],NULL); u_close(outfd); exit(EXIT_SUCCESS); }