CSIS 440 chat client/server project.

server.cpp 1.6KB

    /* Author: Matt Kava Asmt: CSIS 440, Spring 2010, Assignment 6 :: IRC-Like Client/Server Description: A server that implements the SircServer */ #include <iostream> #include <fstream> #include <string> #include <iomanip> #include <stdio.h> #include <stdlib.h> #include "SircServer.h" #include "constants.h" using namespace std; int main(int argc, char* argv[]) { User user = User(); int wkPortRaw = 0; unsigned short wkPort = 0; SircServer server; if(argc > 2) { cerr << "Usage: " << argv[0] << " [Server Port]\n"; cerr << "The server port is optional. \"" << DEFAULT_WKS_PORT << "\" is default.\n"; return 1; } // check the cmdline arguments // get the well-known port number if(argc == 2) { wkPortRaw = atoi(argv[1]); } // confirm it is a valid port number // force to a default if not if(wkPortRaw < 0 || wkPortRaw > 65536) { wkPort = DEFAULT_WKS_PORT; } else { wkPort = DEFAULT_WKS_PORT + (unsigned int)wkPortRaw; } cout << "Server starting and running on port \'" << wkPort << "\'\n"; // cout << "Making server.\n"; server = SircServer(wkPort); // cout << "Made server.\n"; int startValue = server.Startup(); if(startValue == 0) { // no problems. cout << "Server started without issue. Continuing.\n"; } else { cout << "Server statup error: "; switch(startValue) { case 1: { cout << "Socket issue.\n"; break; } case 2: { cout << "Bind issue.\n"; break; } } cout << "Terminating server due to startup error.\n"; return 1; } server.Run(); cout << "Server terminating.\n"; server.Shutdown(); return 0; }