-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.c
More file actions
59 lines (49 loc) · 1.38 KB
/
client.c
File metadata and controls
59 lines (49 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* client.c, copyright 2001 Steve Gribble
*
* The client is a single-threaded program; it sits in a tight
* loop, and in each iteration, it opens a TCP connection to
* the server, sends a request, and reads back a response.
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <ctype.h>
#include <errno.h>
#include "SocketLibrary/socklib.h"
#include "common.h"
/**
* This program should be invoked as "./client hostname portnumber",
* for example, "./client spinlock 4342".
*/
int main(int argc, char **argv) {
int socket_talk, i;
char request[REQUEST_SIZE];
char response[RESPONSE_SIZE];
if (argc != 3) {
fprintf(stderr,
"(CLIENT): Invoke as 'client machine.name.address socknum'\n");
exit(1);
}
// initialize request to some silly data
for (i=0; i<REQUEST_SIZE; i++) {
request[i] = (char) i%255;
}
// spin forever, opening connections, and pushing requests
while(1) {
int result;
// open up a connection to the server
if ((socket_talk = sconnect(argv[1], argv[2])) < 0) {
//////////////////perror("(CLIENT): sconnect");
exit(1);
}
// write the request
result = correct_write(socket_talk, request, REQUEST_SIZE);
if (result == REQUEST_SIZE) {
// read the response
result = correct_read(socket_talk, response, RESPONSE_SIZE);
}
close(socket_talk);
}
return 0;
}