// Owen Sullivan & Lucia Wang
// CPSC 3600-001 F23
// Assignment 1

#include <stdio.h>
#include <unistd.h>

#include "Practical.h"

int main(int argc, char *argv[]) {
    
    // Test for correct number of arguments
    if (argc != 2) {
        
        DieWithUserMessage("Parameter(s)", "<Server Port/Service>");
        
    }

    // First arg: local port
    char *service = argv[1];

    // Create socket for incoming connections
    int servSock = SetupTCPServerSocket(service);
    if (servSock < 0) {
        
        DieWithUserMessage("SetupTCPServerSocket() failed", service);
        
    }

    // Run forever
    for (;;) {
        
        // New connection creates a connected client socket
        int clntSock = AcceptTCPConnection(servSock);

        HandleTCPClient(clntSock);  // Process client
        close(clntSock);
        
        break;
        
    }
    
    // NOT REACHED
    close(servSock);
    
}