#include /* for NULL */ #include /* for perror() */ #include /* for atoi() */ #include /* for pid_t, socket.h */ #include /* for AF_INET, etc. */ #include /* for struct sockaddr_in */ /* Use the values you got from your client here */ #define RESPONSE "gtXXXXx_X_X_XXXXXXX wankle rotary engine" /* Pick a port number for yourself. It should be higher than 2000 or so. * For example, use the last 4 digits of your SSN or your GT number . * You should not exceed 65535, but higher is better. * Change HOST_NAME to be the name of the computer you're running * your server from, too (must be acmex, acmey, or acmez). */ #define HOST_NAME "MYHOST.gatech.edu" #define PORT_NUMBER XXXX /* exit and print system error code */ static void die(char *s) { perror(s); exit(2); } static int main(void) { char sendbuf[BUFSIZ]; char recvbuf[BUFSIZ]; int listenSock, connectSock; struct sockaddr_in listenAddr; struct sockaddr_in connectAddr; int listenSize, connectSize, clientlen; int recvlen; listenSize = sizeof(listenAddr); connectSize = sizeof(connectAddr); memset((char *)&connectAddr,0,connectSize); /*init to 0 */ /* CREATE THE SOCKET */ /* your code here, Hint, use 'socket' */ /* NAME THE SOCKET */ /* This part is done for you */ listenAddr.sin_addr.s_addr = 0; listenAddr.sin_family = AF_INET; listenAddr.sin_port = htons(PORT_NUMBER); /* BIND THE SOCKET */ /* your code here, Hint, use 'bind' */ /* ENABLE LISTENING ON SOCKET */ /* your code here. Hint, use 'listen' */ /* MAIN LOOP -- This loop also more than one connection to be * to your server before it terminates. It's not needed for * this assignment, but allows you to debug without having to * restart the server every time. */ for( ; ; ) { /* clear out buffers initially */ memset((char *)&recvbuf,0,BUFSIZE); memset((char *)&sendbuf,0,BUFSIZE); /* accept the new connection */ /* your code here. Hint, use 'accept' */ /* Create the greeting message in sendbuf */ /* your code here. Hint, use 'sprintf' */ /* Greeting format: \r\n */ /* print the greeting locally */ /* your code here. ie: "Received: text" */ /* send a greeting message to the client */ /* your code here. Hint, use 'send' */ /* read input from client */ /* your code here. Hint, use 'recv' */ /* print out message from client */ /* your code here. ie: "Received: text" */ /* confirm the client message */ /* your code here */ /* Client greeting message will be: "CS2430 Server\r\n" */ /* Authenticate yourself */ /* your code here. Hint, use 'auth' */ /* read input from client */ /* your code here. Hint, use 'recv' */ /* print out message from client */ /* your code here. ie: "Received: text" */ /* confirm the client message */ /* your code here */ /* Client greeting message will be: "getresponse\r\n" */ /* Create the answer message in sendbuf */ /* your code here. Hint, use 'sprintf' */ /* Answer format: \r\n */ /* print out your response */ /* your code here. */ /* send encoded message back to client */ /* your code here. Hint, use 'send' */ /* close the socket */ /* your code here. */ } exit(0); }