MichaelGenchev/CleanNodeServer
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
------------ SERVER ------------ Build a HTTP server (HTTP 1.1) with source IP 127.0.0.2 and port 9999 The server should ONLY accepts POST method requests. When server receive field ask_key=$UNIQUE_ID, server must generate a random 64 bytes string and return it as base64 to the user. The key must be stored in a map/object in the parent's thread and be correlated with the $UNIQUE_ID When server receive field login=$BASE64_KEY, server must check that the key exist in the Map, If it doesn't exist, the server must return 'wrong_key' to the client If the key exist, it must return the $UNIQUE_ID previously generated by the client. When server receives ANYTHING ELSE, it must return 'wrong_query' to the client. ------------ CLIENT ------------ Information to connect to the HTTP server must be passed as argument (IP and port). Client must generate a unique ID, secure 64 bytes, then converted to base64. Client must send ask Server for a random ID by doing a POST request to the server: ask_key=$UNIQUE_ID Client receive the key from the server, then must do another POST request to the server with: login=$BASE64_KEY Server will then reply with the $UNIQUE_ID that we initially sent. Once the server reply with the proper $UNIQUE_ID, the Node program must then RESTART (a true restart) and pass the $UNIQUE_ID as an argument, the argument should then be shown (console.log()) and that's the end of the program, when it restart, it shouldn't connect to the HTTP server, it should just show the . If the server reply with the WRONG $UNIQUE_ID, you must find out the PID (process id) of the server and KILL the server's node process. The server process has to stop entirely. ----------------------- SERVER ADDITIONAL INFO: ----------------------- - The MAP/Object that stores the $UNIQUE_ID of the user must be in the parent thread, you are not allowed to store them in the worker thread. - The HTTP server must be in a Worker Thread, server information are hardcoded in some CONST in the PARENT THREAD, the server info (IP and port) must be passed to the Worker thread AFTER it has been spawned. - Server is startable by command: node server.js ----------------------- CLIENT ADDITIONAL INFO: ----------------------- - The client is another process/js file than the server, it's a different program. - If the server is offline, it should retry connecting/sending to it every 100ms and add delay of 5ms each time (first miss 100ms, then 105ms, then 110ms...) - For the Process Killing if the server reply wrong, you can use any way you want, as long as ONLY the server is killed and not any other node program. This has to work on Linux/Mac if you use Linux/Mac, or Windows if you use Windows, you are allowed to use any solution you want to find out and kill the server's program but strictly no NPM. In order to test this, when we start the server's process, we must be able to pass a parameter to make it always return a wrong $UNIQUE_ID to test. - Client is startable by command: node client.js