Help Please!
Programming Language C++
Assignment
include comments
Client Program
Server
Requirements For this assignment, you will be writing two programs which are designed to talk to each other. One of your programs will be the activation server and the other will be the activation client. Here is the synopsis of how the two programs interact: Server: As the server starts up, it looks to see if the data file (the file of serial nums/machine IDs) exists. If the file does not exist, it will create an empty one. The name of this file is datafile.txt The server binds to a port and awaits connections. Client: The client will look for an activation file. The name of this file is actFile.txt o If the file cannot be found, proceed to attempt activation. o If the file is found, compare the machine ID in the file with the given machine ID to see if they match. If they do not match, proceed to attempt activation. If they do match, the software has already been activated and the program exits. To continue with the activation process, the client now gets a serial number from the user. The client contacts the server. Server: Server accepts the incoming connection Waits for data to be sent. Client: Send the serial number to the server Wait for a reply from the server Server: Receive the serial number . Check to make sure the serial number is valid for the nurnoses of this assignment a valid serial number is any combination of Check to make sure the serial number is valid. For the purposes of this assignment, a valid serial number is any combination of digits. A string containing characters other than digits would be considered to be an invalid serial number. If the serial number is valid o Send a "good" message back to the client . Wait for the next message If the serial number is invalid Send an "invalid" message back to the client o Close the current connection and wait for a new connection from a new client Client: Receive server reply If the reply is "good" o Send the machine ID to the server o Wait for a reply from the server If the reply is "invalid" o Report to the user that the serial number is invalid o Exit the program erver: Receive the machine ID from client - Try to find serial number in the data file If serial number is found o Compare the given machine ID with the one recorded in the data file o If the machine IDs match Send a "good" message back to the client Close the current connection and wait for a new connection from a new client o If the machine IDs do not match Send an "invalid" message back to the client Close the current connection and wait for a new connection from a new client If serial number is not found o Write the serial number and machine ID into the data file o Send a "good" message back to the client o Close the current connection and wait for a new connection from a new client Client: Receive server reply If reply is "good" o Record the machine ID in the activation file o Report to the user that the activation was successful Exit the program If reply is "invalid" o Report to the user that the activation was unsuccessful o Exit the program Note that in the above sequence of communication steps, once the server has either accepted or rejected the activation, it closes the connection and then goes back to waiting for a new connection. Also note, although it isn't specifically listed in the steps above, our server will also display results to the screen to show what's happening. #include
#include #include #include #include using namespace std; // Make sure build environment links to Winsock library file #pragma comment(lib, "Ws2_32.lib"), // Define default global constants #define BUFFERSIZE 256 #define ACTIVATIONFILENAME "actFile.txt" #define IPADDRESS "127.0.0.1" #define GOODMSG "good" #define BADMSG "invalid" #define DEFAULTPORT 6000 // Function to close the specified socket and perform DLL cleanup (WSACleanup) void cleanup (SOCKET socket); Qint main(int argc, char* argv[]) int port; // If user types in a port number on the command line use it, // otherwise, use the default port number if (argc > 1) port = atoi(argv[1]); else port = DEFAULTPORT; 14 16 #define ACTIVATIONFILENAME "actFile.txt" #define IPADDRESS "127.0.0.1" #define GOODMSG "good" #define BADMSG "invalid" #define DEFAULTPORT 6000 17 20 21 // Function to close the specified socket and perform DLL cleanup (WSACleanup) void cleanup (SOCKET socket); 22 Qint main(int argc, char* argv[]), int port; // If user types in a port number on the command line use it, // otherwise, use the default port number if (argc > 1) port = atoi (argv[1]); else port = DEFAULTPORT; return 0; Qvoid cleanup (SOCKET socket) if (socket != INVALID SOCKET), closesocket (socket); WSACleanup(); #include #include #include #include #include using namespace std; // Make sure build environment links to Winsock library file #pragma comment(lib, "Ws2_32.lib"), // Define default global constants #define BUFFERSIZE 256 #define DATAFILENAME "dataFile txt" #define IPADDRESS "127.0.0.1" #define GOODMSG "good" #define BADMSG "invalid" #define DEFAULTPORT 6000 // Function to close the specified socket and perform DLL cleanup (WSACleanup) void cleanup (SOCKET socket); Gint main(int args, char* argv[]), int port; // If user types in a port number on the command line use it, // otherwise, use the default port number if (argc > 1) port = atoi(argv[1]); else port = DEFAULTPORT; #define IPADDRESS "127.0.0.1" #define GOODMSG "good" #define BADMSG "invalid" #define DEFAULTPORT 6000 // Function to close the specified socket and perform DLL cleanup (WSACleanup) void cleanup (SOCKET socket); Qint main(int argc, char* argv[]), int port; // If user types in a port number on the command line use it, // otherwise, use the default port number if (argc > 1) port = atoi(argv[1]); else port = DEFAULTPORT; return 0; Avoid cleanup (SOCKET socket) if (socket != INVALID_SOCKET) closesocket (socket); WSACleanup(); Requirements For this assignment, you will be writing two programs which are designed to talk to each other. One of your programs will be the activation server and the other will be the activation client. Here is the synopsis of how the two programs interact: Server: As the server starts up, it looks to see if the data file (the file of serial nums/machine IDs) exists. If the file does not exist, it will create an empty one. The name of this file is datafile.txt The server binds to a port and awaits connections. Client: The client will look for an activation file. The name of this file is actFile.txt o If the file cannot be found, proceed to attempt activation. o If the file is found, compare the machine ID in the file with the given machine ID to see if they match. If they do not match, proceed to attempt activation. If they do match, the software has already been activated and the program exits. To continue with the activation process, the client now gets a serial number from the user. The client contacts the server. Server: Server accepts the incoming connection Waits for data to be sent. Client: Send the serial number to the server Wait for a reply from the server Server: Receive the serial number . Check to make sure the serial number is valid for the nurnoses of this assignment a valid serial number is any combination of Check to make sure the serial number is valid. For the purposes of this assignment, a valid serial number is any combination of digits. A string containing characters other than digits would be considered to be an invalid serial number. If the serial number is valid o Send a "good" message back to the client . Wait for the next message If the serial number is invalid Send an "invalid" message back to the client o Close the current connection and wait for a new connection from a new client Client: Receive server reply If the reply is "good" o Send the machine ID to the server o Wait for a reply from the server If the reply is "invalid" o Report to the user that the serial number is invalid o Exit the program erver: Receive the machine ID from client - Try to find serial number in the data file If serial number is found o Compare the given machine ID with the one recorded in the data file o If the machine IDs match Send a "good" message back to the client Close the current connection and wait for a new connection from a new client o If the machine IDs do not match Send an "invalid" message back to the client Close the current connection and wait for a new connection from a new client If serial number is not found o Write the serial number and machine ID into the data file o Send a "good" message back to the client o Close the current connection and wait for a new connection from a new client Client: Receive server reply If reply is "good" o Record the machine ID in the activation file o Report to the user that the activation was successful Exit the program If reply is "invalid" o Report to the user that the activation was unsuccessful o Exit the program Note that in the above sequence of communication steps, once the server has either accepted or rejected the activation, it closes the connection and then goes back to waiting for a new connection. Also note, although it isn't specifically listed in the steps above, our server will also display results to the screen to show what's happening. #include #include #include #include #include using namespace std; // Make sure build environment links to Winsock library file #pragma comment(lib, "Ws2_32.lib"), // Define default global constants #define BUFFERSIZE 256 #define ACTIVATIONFILENAME "actFile.txt" #define IPADDRESS "127.0.0.1" #define GOODMSG "good" #define BADMSG "invalid" #define DEFAULTPORT 6000 // Function to close the specified socket and perform DLL cleanup (WSACleanup) void cleanup (SOCKET socket); Qint main(int argc, char* argv[]) int port; // If user types in a port number on the command line use it, // otherwise, use the default port number if (argc > 1) port = atoi(argv[1]); else port = DEFAULTPORT; 14 16 #define ACTIVATIONFILENAME "actFile.txt" #define IPADDRESS "127.0.0.1" #define GOODMSG "good" #define BADMSG "invalid" #define DEFAULTPORT 6000 17 20 21 // Function to close the specified socket and perform DLL cleanup (WSACleanup) void cleanup (SOCKET socket); 22 Qint main(int argc, char* argv[]), int port; // If user types in a port number on the command line use it, // otherwise, use the default port number if (argc > 1) port = atoi (argv[1]); else port = DEFAULTPORT; return 0; Qvoid cleanup (SOCKET socket) if (socket != INVALID SOCKET), closesocket (socket); WSACleanup(); #include #include #include #include #include using namespace std; // Make sure build environment links to Winsock library file #pragma comment(lib, "Ws2_32.lib"), // Define default global constants #define BUFFERSIZE 256 #define DATAFILENAME "dataFile txt" #define IPADDRESS "127.0.0.1" #define GOODMSG "good" #define BADMSG "invalid" #define DEFAULTPORT 6000 // Function to close the specified socket and perform DLL cleanup (WSACleanup) void cleanup (SOCKET socket); Gint main(int args, char* argv[]), int port; // If user types in a port number on the command line use it, // otherwise, use the default port number if (argc > 1) port = atoi(argv[1]); else port = DEFAULTPORT; #define IPADDRESS "127.0.0.1" #define GOODMSG "good" #define BADMSG "invalid" #define DEFAULTPORT 6000 // Function to close the specified socket and perform DLL cleanup (WSACleanup) void cleanup (SOCKET socket); Qint main(int argc, char* argv[]), int port; // If user types in a port number on the command line use it, // otherwise, use the default port number if (argc > 1) port = atoi(argv[1]); else port = DEFAULTPORT; return 0; Avoid cleanup (SOCKET socket) if (socket != INVALID_SOCKET) closesocket (socket); WSACleanup()