-
Notifications
You must be signed in to change notification settings - Fork 1
/
client3.cpp
30 lines (22 loc) · 856 Bytes
/
client3.cpp
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
#include "sockets.hpp"
#include <iostream>
#define CLIENT_NAME "client3"
int main() {
SocketHandler::openSocket(CLIENT_NAME);
std::cout << "Socket open" << std::endl;
SocketHandler::Message com {"\0", "\0", "\0"};
while (1) {
if (SocketHandler::listenClient(&com, (timeval){1,0}) == 0){
printf("Server died\n");
return -1;
}
if (com.send_to != "\0") {
std::cout << "Received from " << com.sent_from << ": " << com.message << std::endl;
com.send_to = "1";
com.sent_from = "3";
SocketHandler::sendMessage(SocketHandler::connection_socket, com);
std::cout << "Sent (" << com.message << ") to " << com.send_to << std::endl;
com = {"\0", "\0", "\0"};
}
}
}