· 7 years ago · Apr 19, 2018, 02:00 AM
1/*-----------------------------------
2 Project: CS 270 Project 5: A Small Server
3 SubName: Small Set
4 Authors: Brad Stephenson & Colton Thompson
5 Date: 4/12/18
6 Version: 1.0
7-----------------------------------
8*/
9/* General Application Requirements:
10 -Take command line parameters: MachineName, port, and SecretKey
11 followed by specifics of the command
12 -MachineName: The DNS name ie.(george.netlab.uky.edu) or the
13 IP address ie.(128.163.146.12) of the maching where the
14 server is running
15 -port: the TCP port number where the server is listening
16 -SecretKey: the number to use as the SecretKey when
17 communicating with the server
18 *Value can be any sequence of characters not exceedint 100 bytes
19 */
20
21/* Small Set Requirements:
22 -Format: smallSet MachineName port SecretKey variableName value
23 -Procedure:
24 -takes a variable name and a value
25 -server sets that variable(internally to the server) to
26 that value
27 -the client prints nothing unless the command fails in
28 which case it prints "failed"
29 */
30
31
32#include <unistd.h> //sleep
33#include "csapp.h"
34
35/*
36 * echoclient.c - An echo client
37 */
38/* $begin echoclientmain */
39
40int EchoClient(int argc, char **argv)
41{
42 int clientfd, port;
43 char *host, buf[MAXLINE];
44 rio_t rio;
45
46 if (argc != 3) {
47 fprintf(stderr, "usage: %s <host> <port>\n", argv[0]);
48 exit(0);
49 }
50 host = argv[1];
51 port = atoi(argv[2]);
52
53 clientfd = Open_clientfd(host, port);
54 Rio_readinitb(&rio, clientfd);
55
56 /*added fill buf*/
57 buf[0] = '1'; buf[1] = '2'; buf[2] = '3';
58
59
60 Rio_writen(clientfd, buf, strlen(buf));
61
62 //if (FD_ISSET(clientfd, &set)
63
64 char BUF[3];
65 Rio_readn(clientfd, BUF, 3); //HANG at this line
66 printf("2\n"); //test
67 printf("CLIENT BUFFER: %c %c %c\n", BUF[0], BUF[1], BUF[2]);
68
69
70 Close(clientfd); //line:netp:echoclient:close
71 sleep(1); //waits for the server to finish
72 exit(0);
73}
74/* $end echoclientmain */
75
76
77int main(int argc, char **argv){
78 printf("Start\n");
79 EchoClient(argc, argv);
80 printf("End\n");
81 return 0;
82}