-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.h
44 lines (32 loc) · 1.09 KB
/
client.h
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
#ifndef CLIENT_H
#define CLIENT_H
#include "network.h"
void printList(std::list<std::string> &l) {
for (std::string s : l) {
std::cout << s << std::endl;
}
}
// RPC which returns a list with char c appended to each string in the
// input list.
std::list<std::string> client_append(int port, std::list<std::string> &l, char c) {
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1) {
std::cout << "error in socket!" << std::endl;
}
struct sockaddr_in addr;
addr.sin_family = AF_INET;
struct hostent *host = gethostbyname("localhost");
memcpy(&(addr.sin_addr), host->h_addr, host->h_length);
addr.sin_port = htons(port);
if(connect(sockfd, (sockaddr *) &addr, sizeof(addr)) == -1) {
std::cout << "error in connect!" << std::endl;
}
// CONNECTED TO SERVER.
// TODO: Finish client stub.
// (1) Send the char to append.
// (2) Send the list.
// (3) Receive the list back from the server.
// (4) Close the socket.
return std::list<std::string>();
}
#endif