server connects with multiple clients with select
- On connection server sends successful connection message
- client processes each and every command with a check_command function to check if the command format is right.
- server processes each command by a relay of messages of sending actual information and acknowledgement messages with client. In the client side client only checks if a acknowledge message is recieved and prints a successful command message.
- This also helps server to send error messages during acknowledgement and to send successful command messages.
- The server file upload is limited to 1024 lines per line of file.
- each files that has been uploaded to the server is kept at a designated folder called server_files, server program at each initiation checks if the server_files directory exists or not and keeps each file with the same name in that directory.
- for multiple clients to send invites a child process waits for message from server and keeps on asking for input from client on invite answer until a proper "yes/no".
- for client ids server side keeps an array of string "client_ids" to keep ids saved, each id is generated 5 digit long random number string.
- each file uploaded server keeps an extra file with all the information about the file with the name suffixed with "perm_". informations are in order filename, no of lines, owner, list of collaborators with permission.
- For invitation each invitation server sends a request to the respective client at the moment any invitation comes to the server. server then waits for the respective client to send a definitive answer then server change the permission of the file and sends results to the owner.
- on upload server creates a permission file(containing filename, no of lines, and collaborators) and edits a user file named with "client_ids" to store the file names the user will upload.
For all other commands:
-
/users: View all active clients lists with numbered according to the server
-
/files: View all files that have been uploaded to the server, along with all details (owners, collaborators, permissions and the no. of lines in the file).
-
/upload : Upload the local file filename to the server
-
/download : Download the server file filename to the client, if given client has permission to access that file
-
/invite <client_id> : Invite client client_id to join as collaborator for file filename (should already be present on server). permission can be either of V/E signifying viewer/editor.
-
/read <start_idx> <end_idx>: Read from file filename starting from line index start_idx to end_idx . If only one index is specified, read that line. If none are specified, read the entire file.
-
/insert “”: Write message at the line number specified by idx into file filename . If idx is not specified, insert at the end. Quotes around the message to demarcate it from the other fields.
-
/delete <start_idx> <end_idx>: Delete lines starting from line index start_idx to end_idx from file filename. If only one index is specified, delete that line. If none are specified, delete the entire contents of the file.
-
/exit: Disconnects from the server, and then all files which this client owned should be deleted at the server, and update the permission file.
run server file with "g++ server.cpp -o server && ./server" run the client using "g++ client.cpp -o client && ./client"