Thread: multi-threaded file transfer with socket

  1. #1
    Registered User
    Join Date
    Mar 2014
    Posts
    95

    multi-threaded file transfer with socket

    I try to make multi-threaded server-client file transfer system in C. There are clients which will send or list or do other choice(in switch case you can see) and a server storing the files and serve alot clients. Multi-thread ideology is really difficult as far as I see it needs too much experience instead of knowledge. I have been working on the project more than one week so no longer I get on top of the problems. There are 4 choices first one is lists local files of client in its directory, second one is list files which are transferred between the client and server, third reading filename from user and copy the file into server's directory. My vital issue is here about multi-threading I cannot connect multiple clients. I have read the code from a to z heaps of times but I really can't catch my wrong and am stuck so. The other issue is that the client will be end when the SIGINT is catched but for instance after choosing list files when press ctrl-c it doesn't stop. Same issue is for the server file as well it more troublesome rather than client's catching because when server gets SIGINT, clients will be disconnected respectively then server. Thanks for your helps!

    server.c

    Code:
        /*
         Soner
         Receive a file over a socket.
         
         Saves it to output.tmp by default.
         
         Interface:
         
         ./executable [<port>]
         
         Defaults:
         
         - output_file: output.tmp
         - port: 12345
         */
        
        #define _XOPEN_SOURCE 700
        
        #include <stdio.h>
        #include <stdlib.h>
        #include <string.h>
        
        #include <arpa/inet.h>
        #include <fcntl.h>
        #include <netdb.h> /* getprotobyname */
        #include <netinet/in.h>
        #include <sys/stat.h>
        #include <sys/socket.h>
        #include <unistd.h>
        
        #include <pthread.h>
        
        pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
        
        enum { PORTSIZE = 5 };
        
        void* forClient(void* ptr);
        void sig_handler(int signo)
        {
            if (signo == SIGINT)
                printf("!!  OUCH,  CTRL - C received  by server !!\n");
        }
        
        int main(int argc, char **argv) {
            struct addrinfo hints, *res;
            int enable = 1;
            int filefd;
            int server_sockfd;
            unsigned short server_port = 12345u;
            char portNum[PORTSIZE];
            
            socklen_t client_len[BUFSIZ];
            struct sockaddr_in client_address[BUFSIZ];
            int client_sockfd[BUFSIZ];
            int socket_index = 0;
            
            pthread_t threads[BUFSIZ];
            
            if (argc != 2) {
                fprintf(stderr, "Usage   ./server  <port>\n");
                exit(EXIT_FAILURE);
            }
            server_port = strtol(argv[1], NULL, 10);
            
            memset(&hints, 0, sizeof hints);
            hints.ai_family = AF_INET;       //ipv4
            hints.ai_socktype = SOCK_STREAM; // tcp
            hints.ai_flags = AI_PASSIVE;     // fill in my IP for me
            
            sprintf(portNum, "%d", server_port);
            getaddrinfo(NULL, portNum, &hints, &res);
            
            server_sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
            if (server_sockfd == -1) {
                perror("socket");
                exit(EXIT_FAILURE);
            }
            
            if (setsockopt(server_sockfd, SOL_SOCKET, (SO_REUSEPORT | SO_REUSEADDR), &enable, sizeof(enable)) < 0) {
                perror("setsockopt(SO_REUSEADDR) failed");
                exit(EXIT_FAILURE);
            }
            
            if (bind(server_sockfd, res->ai_addr, res->ai_addrlen) == -1) {
                perror("bind");
                exit(EXIT_FAILURE);
            }
            
            if (listen(server_sockfd, 5) == -1) {
                perror("listen");
                exit(EXIT_FAILURE);
            }
            fprintf(stderr, "listening on port %d\n", server_port);
            
            
            while (1) {
                client_len[socket_index] = sizeof(client_address[socket_index]);
                puts("waiting for client");
                client_sockfd[socket_index] = accept(
                                       server_sockfd,
                                       (struct sockaddr*)&client_address[socket_index],
                                       &client_len[socket_index]
                                       );
                if (client_sockfd[socket_index] < 0) {
                    perror("Cannot accept connection\n");
                    close(server_sockfd);
                    exit(EXIT_FAILURE);
                }
        
                pthread_create( &threads[socket_index], NULL, forClient, (void*)client_sockfd[socket_index]);
                
                if(BUFSIZ == socket_index) {
                    socket_index = 0;
                } else {
                    ++socket_index;
                }
                
                pthread_join(threads[socket_index], NULL);
                close(filefd);
                close(client_sockfd[socket_index]);
            }
            return EXIT_SUCCESS;
        }
        void* forClient(void* ptr) {
            int connect_socket = (int) ptr;
            int filefd;
            ssize_t read_return;
            char buffer[BUFSIZ];
            char *file_path;
            char receiveFileName[BUFSIZ];
            
            int ret = 1;
            // Thread number means client's id
            printf("Thread number %ld\n", pthread_self());
            pthread_mutex_lock( &mutex1 );
        
            // until stop receiving go on taking information
            while (recv(connect_socket, receiveFileName, sizeof(receiveFileName), 0)) {
                
                file_path = receiveFileName;
                
                fprintf(stderr, "is the file name received? ?   =>  %s\n", file_path);
                
                filefd = open(file_path,
                              O_WRONLY | O_CREAT | O_TRUNC,
                              S_IRUSR | S_IWUSR);
                if (filefd == -1) {
                    perror("open");
                    exit(EXIT_FAILURE);
                }
                do {
                    read_return = read(connect_socket, buffer, BUFSIZ);
                    if (read_return == -1) {
                        perror("read");
                        exit(EXIT_FAILURE);
                    }
                    if (write(filefd, buffer, read_return) == -1) {
                        perror("write");
                        exit(EXIT_FAILURE);
                    }
                } while (read_return > 0);
            }
            
            pthread_mutex_unlock( &mutex1 );
            
            fprintf(stderr, "Client dropped connection\n");
            pthread_exit(&ret);
        }

    client.c
    Code:
    
    
        /*
         Soner
         Send a file over a socket.
         
         Interface:
         
         ./executable [<sever_hostname> [<port>]]
         
         Defaults:
         
         - server_hostname: 127.0.0.1
         - port: 12345
         */
        
        #define _XOPEN_SOURCE 700
        
        #include <stdio.h>
        #include <stdlib.h>
        #include <string.h>
        
        #include <signal.h>
        
        #include <arpa/inet.h>
        #include <fcntl.h>
        #include <netdb.h> /* getprotobyname */
        #include <netinet/in.h>
        #include <sys/stat.h>
        #include <sys/socket.h>
        #include <unistd.h>
        
        enum { PORTSIZE = 5 };
        
        void sig_handler(int signo)
        {
            if (signo == SIGINT)
                printf("!!  OUCH,  CTRL - C received on client  !!\n");
        }
        
        int main(int argc, char **argv) {
            struct addrinfo hints, *res;
            char *server_hostname = "127.0.0.1";
            char file_path[BUFSIZ];
            char *server_reply = NULL;
            char *user_input = NULL;
            char buffer[BUFSIZ];
            int filefd;
            int sockfd;
            ssize_t read_return;
            struct hostent *hostent;
            unsigned short server_port = 12345;
            char portNum[PORTSIZE];
            char remote_file[BUFSIZ];
            int select;
            //char filename_to_send[BUFSIZ];
        
            if (argc != 3) {
                fprintf(stderr, "Usage   ./client  <ip>  <port>\n");
                exit(EXIT_FAILURE);
            }
            
            server_hostname = argv[1];
            server_port = strtol(argv[2], NULL, 10);
        
            
            /* Prepare hint (socket address input). */
            hostent = gethostbyname(server_hostname);
            if (hostent == NULL) {
                fprintf(stderr, "error: gethostbyname(\"%s\")\n", server_hostname);
                exit(EXIT_FAILURE);
            }
            
            memset(&hints, 0, sizeof hints);
            hints.ai_family = AF_INET;       //ipv4
            hints.ai_socktype = SOCK_STREAM; // tcp
            hints.ai_flags = AI_PASSIVE;     // fill in my IP for me
            
            sprintf(portNum, "%d", server_port);
            getaddrinfo(NULL, portNum, &hints, &res);
            
            sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
            if (sockfd == -1) {
                perror("socket");
                exit(EXIT_FAILURE);
            }
            
            /* Do the actual connection. */
            if (connect(sockfd, res->ai_addr, res->ai_addrlen) == -1) {
                perror("connect");
                return EXIT_FAILURE;
            }
            
            
            while(1) {
                if (signal(SIGINT, sig_handler))
                    break;
                
                puts("connected to the server");
                puts("-----------------");
                puts("|1 - listLocal| \n|2 - listServer| \n|3 - sendFile| \n|4 - help| \n");
                puts("-----------------");
                scanf("%d", &select);
                switch (select) {
                        // list files of client's directory
                    case 1:
                        system("find . -maxdepth 1 -type f | sort");
                        break;
                        // send file
                    case 4:
                        fgets(file_path, sizeof BUFSIZ - 1, stdin);
                        
                        // send file name to server
                        sprintf(remote_file, "%s", file_path);
                        send(sockfd, remote_file, sizeof(remote_file), 0);
                        
                        filefd = open(file_path, O_RDONLY);
                        if (filefd == -1) {
                            perror("open");
                            exit(EXIT_FAILURE);
                        }
                        while (1) {
                            read_return = read(filefd, buffer, BUFSIZ);
                            if (read_return == 0)
                                break;
                            if (read_return == -1) {
                                perror("read");
                                exit(EXIT_FAILURE);
                            }
                            if (write(sockfd, buffer, read_return) == -1) {
                                perror("write");
                                exit(EXIT_FAILURE);
                            }
                        }
                        close(filefd);
                        break;
                        
                    case 5:
                        free(user_input);
                        free(server_reply);
                        exit(EXIT_SUCCESS);
                        
                    default:
                        puts("Wrong selection!");
                }
            }
            
            free(user_input);
            free(server_reply);
            exit(EXIT_SUCCESS);
        }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > pthread_join(threads[socket_index], NULL);
    > close(filefd);
    Well the big problem is you create a thread, then wait to join it. So you never actually have more than one thread going at once.
    Also, filefd here is an uninitialised variable, so who knows what descriptor you're closing. You could be trashing stdin for all you know.

    > pthread_exit(&ret);
    ret is a local variable that will go out of scope when the thread ends, and renders the pointer invalid.

    > unsigned short server_port = 12345;
    > char portNum[PORTSIZE];
    PORTSIZE is 5, which is 1 byte short of being able to store "12345\0" as a string.

    > fgets(file_path, sizeof BUFSIZ - 1, stdin);
    There is no need for -1 here; fgets() knows to count the \0 in the amount of usable space.

    > sprintf(remote_file, "%s", file_path);
    > send(sockfd, remote_file, sizeof(remote_file), 0);
    Do you know the difference between sizeof() and strlen() here?
    You're sending a string, and a whole bunch of garbage to the receiver.

    There are some other things as well, but this will do for now.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2014
    Posts
    95
    Quote Originally Posted by Salem View Post
    > pthread_join(threads[socket_index], NULL);
    > close(filefd);
    Well the big problem is you create a thread, then wait to join it. So you never actually have more than one thread going at once.
    Also, filefd here is an uninitialised variable, so who knows what descriptor you're closing. You could be trashing stdin for all you know.

    > pthread_exit(&ret);
    ret is a local variable that will go out of scope when the thread ends, and renders the pointer invalid.

    > unsigned short server_port = 12345;
    > char portNum[PORTSIZE];
    PORTSIZE is 5, which is 1 byte short of being able to store "12345\0" as a string.

    > fgets(file_path, sizeof BUFSIZ - 1, stdin);
    There is no need for -1 here; fgets() knows to count the \0 in the amount of usable space.

    > sprintf(remote_file, "%s", file_path);
    > send(sockfd, remote_file, sizeof(remote_file), 0);
    Do you know the difference between sizeof() and strlen() here?
    You're sending a string, and a whole bunch of garbage to the receiver.

    There are some other things as well, but this will do for now.

    Thanks a lot. I have fixed some issues. But still I have vital issue that when I want to send file with choice 3 then write file name, the connection is gone.I mean also I can't send more files .The server can't receive other choices. Is there any solution for me?

    server.c

    Code:
    /*
     Soner
     Receive a file over a socket.
     
     Saves it to output.tmp by default.
     
     Interface:
     
     ./executable [<port>]
     
     Defaults:
     
     - output_file: output.tmp
     - port: 12345
     */
    
    
    #define _XOPEN_SOURCE 700
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <signal.h>
    
    
    #include <arpa/inet.h>
    #include <fcntl.h>
    #include <netdb.h>                      /* getprotobyname */
    #include <netinet/in.h>
    #include <sys/stat.h>
    #include <sys/socket.h>
    #include <unistd.h>
    
    
    #include <pthread.h>
    
    
    struct client {
        socklen_t client_len;
        struct sockaddr_in client_address;
        int client_sockfd;
        pthread_t thread;
    };
    
    
    
    
    // NOTE: provide enough space for a 5 digit port + EOS char
    enum { PORTSIZE = 6 };
    
    
    double cpu_time_used;
    clock_t start, end;
    
    
    
    
    void *forClient(void *ptr);
    
    
    void portCleaner(const char* port_num) {
        char temp[100] = "sudo lsof -t -i tcp:";
        sprintf(temp, "%s%s%s", temp, port_num, " | xargs kill -9;");
        system(temp);
        //puts(temp);
    }
    
    
    void
    sig_handler(int signo)
    {
        if (signo == SIGINT)
            printf("!!  OUCH,  CTRL - C received  by server !!\n");
    }
    
    
    int
    main(int argc, char **argv)
    {
        struct addrinfo hints,
        *res;
        int enable = 1;
        //int filefd;  // NOTE: this is never initialized/used
        int server_sockfd;
        unsigned short server_port = 12345u;
        char portNum[PORTSIZE];
        struct sockaddr_in server_address;
        struct protoent *protoent;
        char protoname[] = "tcp";
    
    
    
    
        
    #if 0
        int socket_index = 0;
    #else
        struct client *ctl;
    #endif
        
        if (argc != 2) {
            fprintf(stderr, "Usage   ./server  <port>\n");
            exit(EXIT_FAILURE);
        }
        server_port = strtol(argv[1], NULL, 10);
        
        /* Create a socket and listen to it.. */
        protoent = getprotobyname(protoname);
        if (protoent == NULL) {
            perror("getprotobyname");
            exit(EXIT_FAILURE);
        }
        server_sockfd = socket(
                               AF_INET,
                               SOCK_STREAM,
                               protoent->p_proto
                               );
        if (server_sockfd == -1) {
            perror("socket");
            exit(EXIT_FAILURE);
        }
        if (setsockopt(server_sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable)) < 0) {
            perror("setsockopt(SO_REUSEADDR) failed");
            exit(EXIT_FAILURE);
        }
        server_address.sin_family = AF_INET;
        server_address.sin_addr.s_addr = htonl(INADDR_ANY);
        server_address.sin_port = htons(server_port);
        if (bind(
                 server_sockfd,
                 (struct sockaddr*)&server_address,
                 sizeof(server_address)
                 ) == -1
            ) {
            perror("bind");
            portCleaner(argv[1]);
            exit(EXIT_FAILURE);
        }
        if (listen(server_sockfd, 5) == -1) {
            perror("listen");
            exit(EXIT_FAILURE);
        }
        fprintf(stderr, "listening on port %d\n", server_port);
        
    
    
        pthread_attr_t attr;
        pthread_attr_init(&attr);
        pthread_attr_setdetachstate(&attr,1);
        
        start = clock();
        
        while (1) {
    
    
    
    
            ctl = malloc(sizeof(struct client));
            if (ctl == NULL) {
                perror("malloc");
                exit(EXIT_FAILURE);
            }
            
            ctl->client_len = sizeof(ctl->client_address);
            puts("waiting for client");
            
            ctl->client_sockfd = accept(server_sockfd,
                                        (struct sockaddr *) &ctl->client_address, &ctl->client_len);
            
            if (ctl->client_sockfd < 0) {
                perror("Cannot accept connection\n");
                close(server_sockfd);
                exit(EXIT_FAILURE);
            }
    
    
            pthread_create(&ctl->thread, &attr, forClient, ctl);
    
    
        }
        
        return EXIT_SUCCESS;
    }
    
    
    void *
    forClient(void *ptr)
    {
        
        end = clock();
        cpu_time_used = 1000 * (((double) (end - start)) / CLOCKS_PER_SEC);
    #if 0
        int connect_socket = (int) ptr;
    #else
        struct client *ctl = ptr;
        int connect_socket = ctl->client_sockfd;
    #endif
        int filefd;
        ssize_t read_return;
        char buffer[BUFSIZ];
        char *file_path;
        char receiveFileName[BUFSIZ];
        char cmd[BUFSIZ];
    
    
        // Thread number means client's id
        printf("Connected time  [%lf] ---  Thread number [%ld]\n", cpu_time_used, pthread_self());
        
    
    
        
        // until stop receiving go on taking information
        while (recv(connect_socket, receiveFileName, sizeof(receiveFileName), 0)) {
    
    
            if((strcmp(receiveFileName, "listServer") == 0
               || strcmp(receiveFileName, "listLocal") == 0 || strcmp(receiveFileName, "help") == 0
                || strcmp(receiveFileName, "exit") == 0 || strcmp(receiveFileName, "sendFile") == 0)) {
                printf("--- Command <%s> ---\n", receiveFileName);
                continue;
            }
            
            file_path = receiveFileName;
            
            fprintf(stderr, "is the file name received? ?   =>  %s\n", file_path);
            
            filefd = open(file_path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
            if (filefd == -1) {
                perror("open");
                exit(EXIT_FAILURE);
            }
            do {
                read_return = read(connect_socket, buffer, BUFSIZ);
                if (read_return == -1) {
                    perror("read");
                    exit(EXIT_FAILURE);
                }
                if (write(filefd, buffer, read_return) == -1) {
                    perror("write");
                    exit(EXIT_FAILURE);
                }
            } while (read_return > 0);
            
            // NOTE/BUG: filefd was never closed
            close(filefd);
            
        }
        
        fprintf(stderr, "Client dropped connection\n");
        
        // NOTE: do all client related cleanup here
        // previously, the main thread was doing the close, which is why it had
        // to do the pthread_join
        close(connect_socket);
        free(ctl);
        
        return (void *) 0;
    }
    client.c

    Code:
    /*
     Soner
     Send a file over a socket.
     
     Interface:
     
     ./executable [<sever_hostname> [<port>]]
     
     Defaults:
     
     - server_hostname: 127.0.0.1
     - port: 12345
     */
    
    
    #define _XOPEN_SOURCE 700
    
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    #include <signal.h>
    
    
    #include <arpa/inet.h>
    #include <fcntl.h>
    #include <netdb.h>                      /* getprotobyname */
    #include <netinet/in.h>
    #include <sys/stat.h>
    #include <sys/socket.h>
    #include <unistd.h>
    
    
    // NOTE/BUG: this didn't provide enough space for a 5 digit port + EOS char
    #if 0
    enum { PORTSIZE = 5 };
    #else
    enum { PORTSIZE = 6 };
    #endif
    
    
    void
    sig_handler(int signo)
    {
        if (signo == SIGINT)
            printf("!!  OUCH,  CTRL - C received on client  !!\n");
    }
    
    
    int
    main(int argc, char **argv)
    {
        struct addrinfo hints,
        *res;
        char *server_hostname = "127.0.0.1";
        char file_path[BUFSIZ];
        char *server_reply = NULL;
        char *user_input = NULL;
        char buffer[BUFSIZ];
        int filefd;
        int sockfd;
        ssize_t read_return;
        struct hostent *hostent;
        unsigned short server_port = 12345;
        char portNum[PORTSIZE];
        char remote_file[BUFSIZ];
        int select;
        char *client_server_files[BUFSIZ];
        int i = 0;
        int j;
        char protoname[] = "tcp";
        struct protoent *protoent;
        struct sockaddr_in sockaddr_in;
        in_addr_t in_addr;
    
    
        
        // char filename_to_send[BUFSIZ];
        
        if (argc != 3) {
            fprintf(stderr, "Usage   ./client  <ip>  <port>\n");
            exit(EXIT_FAILURE);
        }
        
        server_hostname = argv[1];
        server_port = strtol(argv[2], NULL, 10);
        
        
        /* Get socket. */
        protoent = getprotobyname(protoname);
        if (protoent == NULL) {
            perror("getprotobyname");
            exit(EXIT_FAILURE);
        }
        sockfd = socket(AF_INET, SOCK_STREAM, protoent->p_proto);
        if (sockfd == -1) {
            perror("socket");
            exit(EXIT_FAILURE);
        }
        /* Prepare sockaddr_in. */
        hostent = gethostbyname(server_hostname);
        if (hostent == NULL) {
            fprintf(stderr, "error: gethostbyname(\"%s\")\n", server_hostname);
            exit(EXIT_FAILURE);
        }
        in_addr = inet_addr(inet_ntoa(*(struct in_addr*)*(hostent->h_addr_list)));
        if (in_addr == (in_addr_t)-1) {
            fprintf(stderr, "error: inet_addr(\"%s\")\n", *(hostent->h_addr_list));
            exit(EXIT_FAILURE);
        }
        sockaddr_in.sin_addr.s_addr = in_addr;
        sockaddr_in.sin_family = AF_INET;
        sockaddr_in.sin_port = htons(server_port);
        
        /* Do the actual connection. */
        if (connect(sockfd, (struct sockaddr*)&sockaddr_in, sizeof(sockaddr_in)) == -1) {
            perror("connect");
            return EXIT_FAILURE;
        }
        while (1) {
            if (signal(SIGINT, sig_handler)) {
                break;
            }
            
            puts("connected to the server");
            puts("-----------------");
            puts("|1 - listLocal| \n|2 - listServer| \n|3 - sendFile| \n|4 - help| \n|5 - exit| ");
            puts("-----------------");
            while (1) {
                printf("------%d",select);
                scanf("%d", &select);
                while ( getchar() != '\n' );
    
    
                
                switch (select) {
                    case 1: // list files of client's directory
                        system("find . -maxdepth 1 -type f | sort");
                        sprintf(remote_file, "%s", "listLocal");
                        send(sockfd, remote_file, sizeof(remote_file), 0);
                        break;
                        
                    case 2: // listServer
                        sprintf(remote_file, "%s", "listServer");
                        send(sockfd, remote_file, sizeof(remote_file), 0);
                        puts("---- Files btw Server and the Client ----");
                        for (j = 0; j < i; ++j) {
                            puts(client_server_files[j]);
                        }
                        break;
                        
                    case 3: // send file
                        memset(file_path, 0, sizeof file_path);
                        scanf("%s", file_path);
                        
                        sprintf(remote_file, "%s", "sendFile");
                        send(sockfd, remote_file, sizeof(remote_file), 0);
                        
                        memset(remote_file, 0, sizeof remote_file);
                        // send file name to server
                        sprintf(remote_file, "%s", file_path);
                        send(sockfd, remote_file, sizeof(remote_file), 0);
                        
                        filefd = open(file_path, O_RDONLY);
                        if (filefd == -1) {
                            perror("open send file");
                            //exit(EXIT_FAILURE);
                            break;
                        }
                        
                        while (1) {
                            read_return = read(filefd, buffer, BUFSIZ);
                            if (read_return == 0)
                                break;
                            if (read_return == -1) {
                                perror("read");
                                //exit(EXIT_FAILURE);
                                break;
                            }
                            if (write(sockfd, buffer, read_return) == -1) {
                                perror("write");
                                //exit(EXIT_FAILURE);
                                break;
                            }
                        }
                        
                        // add files in char pointer array
                        client_server_files[i++] = file_path;
                        
                        close(filefd);
                        break;
                        
                    case 5:
                        sprintf(remote_file, "%s", "exit");
                        send(sockfd, remote_file, sizeof(remote_file), 0);
                        free(user_input);
                        free(server_reply);
                        exit(EXIT_SUCCESS);
                        
                    default:
                        puts("Wrong selection!");
                        break;
                }
    
    
            }
        }
        
        free(user_input);
        free(server_reply);
        exit(EXIT_SUCCESS);
    }
    Last edited by Ph0x; 05-29-2016 at 11:33 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Going from single-threaded to multi-threaded
    By Dino in forum C Programming
    Replies: 11
    Last Post: 03-23-2008, 01:14 PM
  2. Multi-Threaded Server Help
    By jonswits20 in forum C# Programming
    Replies: 5
    Last Post: 04-17-2007, 11:05 PM
  3. gdb problem in multi-threaded app
    By IfYouSaySo in forum Linux Programming
    Replies: 1
    Last Post: 10-12-2006, 08:22 PM
  4. multi threaded program
    By Dash_Riprock in forum C++ Programming
    Replies: 6
    Last Post: 08-27-2006, 08:38 AM
  5. Multi-Threaded Sockets
    By XSquared in forum Networking/Device Communication
    Replies: 9
    Last Post: 08-28-2003, 09:54 PM

Tags for this Thread