Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b56e831048
Fetching contributors…

Cannot retrieve contributors at this time

file 54 lines (47 sloc) 1.298 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/**
* @file main.c
* @brief switch server or client
* @author Airead Fan <fgh1987168@gmail.com>
* @date 2012 2月 21 15:04:30 CST
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "server.h"
#include "client.h"

/**
* @brief main function
*
* It is just a switch by which you chose to run server or client.
*
* @todo check ip address and port validity
*/
int main(int argc, char *argv[])
{
    char *ip_addr;
    unsigned short port;

    if (argc < 4) {
        fprintf(stderr, "usage: %s <server/client> <ip_addr> <port>\n", argv[0]);
        exit(1);
    }

    /* TODO: check ip address and port validity */
    ip_addr = argv[2];
    port = strtol(argv[3], NULL, 10);
    
    if (strcmp(argv[1], "server") == 0
        || strcmp(argv[1], "s") == 0) {
        if (server_main(ip_addr, port) < 0) {
            fprintf(stderr, "start server_main failed\n");
            exit(1);
        }
    } else if (strcmp(argv[1], "client") == 0
               || strcmp(argv[1], "c") == 0) {
        if (client_main(ip_addr, port) < 0) {
            fprintf(stderr, "start server_main failed\n");
            exit(1);
        }
    } else {
        fprintf(stderr, "usage: %s <server/client> <ip_addr> <port>\n", argv[0]);
        exit(1);
    }
    
    return 0;
}
Something went wrong with that request. Please try again.