Question: Server.c file /* server.c */ #include #include #include #define BUFFSIZE 256 #define INPUT_PROMPT Input > #define RECEIVED_PROMPT Received> int recvln(connection, char *, int);
Server.c file
/* server.c */
#include
#define BUFFSIZE 256 #define INPUT_PROMPT "Input > " #define RECEIVED_PROMPT "Received> "
int recvln(connection, char *, int); int readln(char *, int);
/*----------------------------------------------------------------------- * * Program: chatserver * Purpose: wait for a connection from a chatclient & allow users to chat * Usage: chatserver
if (argc != 2) { (void) fprintf(stderr, "usage: %s
(void) printf("Chat Server Waiting For Connection. ");
/* wait for a connection from a chatclient */
conn = await_contact((appnum) atoi(argv[1])); if (conn < 0) exit(1);
(void) printf("Chat Connection Established. ");
/* iterate, reading from the client and the local user */
while((len = recvln(conn, buff, BUFFSIZE)) > 0) { (void) printf(RECEIVED_PROMPT); (void) fflush(stdout); (void) write(STDOUT_FILENO, buff, len);
/* send a line to the chatclient */
(void) printf(INPUT_PROMPT); (void) fflush(stdout); if ((len = readln(buff, BUFFSIZE)) < 1) break; buff[len - 1] = ' '; (void) send(conn, buff, len, 0); }
/* iteration ends when EOF found on stdin or chat connection */
(void) send_eof(conn); (void) printf(" Chat Connection Closed. "); return 0; }
============================================================================================================
client.c file
/* client.c */
#include
#define BUFFSIZE 256 #define INPUT_PROMPT "Input > " #define RECEIVED_PROMPT "Received> "
int recvln(connection, char *, int); int readln(char *, int);
/*----------------------------------------------------------------------- * * Program: chatclient * Purpose: contact a chatserver and allow users to chat * Usage: chatclient
if (argc != 3) { (void) fprintf(stderr, "usage: %s
/* convert the compname to binary form comp */
comp = cname_to_comp(argv[1]); if (comp == -1) exit(1);
/* make a connection to the chatserver */
conn = make_contact(comp, (appnum) atoi(argv[2])); if (conn < 0) exit(1);
(void) printf("Chat Connection Established. "); (void) printf(INPUT_PROMPT); (void) fflush(stdout);
/* iterate, reading from local user and then from chatserver */
while((len = readln(buff, BUFFSIZE)) > 0) { buff[len - 1] = ' '; (void) send(conn, buff, len, 0);
/* receive and print a line from the chatserver */ if ((len = recvln(conn, buff, BUFFSIZE)) < 1) break; (void) printf(RECEIVED_PROMPT); (void) fflush(stdout); (void) write(STDOUT_FILENO, buff, len);
(void) printf(INPUT_PROMPT); (void) fflush(stdout); }
/* iteration ends when stdin or the connection indicates EOF */
(void) printf(" Chat Connection Closed. "); (void) send_eof(conn); exit(0); }
Question : Design and implement a login protocol so that after the client connects to the server, the server authenticates the client first. Only after a client enters a correct password, the server can start chatting with the client. On the server side, there is an ASCII text file passwd.txt, where all users names and passwords are stored, in the format of name::password, one line for each user without spaces.
text file:
user1::password1 crazyjambo::bsdh*shR imnew::bh*bh@s
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
