-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_client.cc
58 lines (50 loc) · 1.04 KB
/
demo_client.cc
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
// demo client
#include <string>
#include "demo_protocol.h"
#include "rpc.h"
#include <vector>
#include <arpa/inet.h>
#include <sstream>
#include <iostream>
#include <stdio.h>
// Client interface to the demo server
class demo_client {
protected:
rpcc *cl;
public:
demo_client(std::string d);
virtual ~demo_client() {};
virtual demo_protocol::status stat(demo_protocol::demoVar);
};
demo_client::demo_client(std::string dst)
{
sockaddr_in dstsock;
make_sockaddr(dst.c_str(), &dstsock);
cl = new rpcc(dstsock);
if (cl->bind() < 0) {
printf("demo_client: call bind\n");
}
}
int
demo_client::stat(demo_protocol::demoVar var)
{
int r;
demo_protocol::status ret = cl->call(demo_protocol::stat, cl->id(), var, r);
VERIFY (ret == demo_protocol::OK);
return r;
}
std::string dst;
demo_client *dc;
int
main(int argc, char *argv[])
{
int r;
if(argc != 2){
fprintf(stderr, "Usage: %s [host:]port\n", argv[0]);
exit(1);
}
dst = argv[1];
dc = new demo_client(dst);
r = dc->stat(1);
printf ("stat returned %d\n", r);
}