1 #include "tcp_client.h"
2
main(int c,char ** argv)3 int main(int c, char** argv)
4 {
5 char* host = "www.mysql.com";
6 int port = 80;
7 int sec_timeout = 2;
8 char* log_file = NULL;
9 FILE* log;
10
11
12 if(c > 5) c = 5;
13
14 switch(c)
15 {
16 case 5: sec_timeout = 2;
17 case 4: log_file = argv[3];
18 case 3: port = atoi(argv[2]);
19 case 2: host = argv[1];
20 }
21
22 if(log_file)
23 {
24 log = fopen(log_file, "a");
25 if(!log)
26 {
27 fprintf(stderr, "Could not open log file %s: %s\n", log_file,
28 strerror(errno));
29 exit(1);
30 }
31 }
32 else
33 log = stderr;
34
35 char buffer[2048];
36 TcpClient client(host,port, log);
37 TcpClient client1(host,port, log);
38 if(!client)
39 exit(1);
40 if(!client1)
41 exit(1);
42
43 client.connect(sec_timeout);
44 client1.connect(sec_timeout);
45
46 if(!client)
47 {
48 exit(1);
49 }
50
51
52 if(!client1)
53 {
54 exit(1);
55 }
56
57 client.send("GET / HTTP/1.0\n\n", strlen("GET / HTTP/1.0\n\n"));
58 int bytes_read;
59 bytes_read = client.receive(buffer, 2048);
60
61 do
62 {
63 cout.write(buffer, bytes_read);
64 bytes_read = client.receive(buffer, 2048);
65 } while(bytes_read > 0);
66
67
68 }
69
70
71