-
Notifications
You must be signed in to change notification settings - Fork 1
/
client1.cpp
36 lines (26 loc) · 1.08 KB
/
client1.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
31
32
33
34
35
36
#include "sockets.hpp"
#include <iostream>
#define CLIENT_NAME "client1"
int main() {
SocketHandler::openSocket(CLIENT_NAME);
std::cout << "Socket open" << std::endl;
SocketHandler::Message com {"2", "1", "bom dia"};
SocketHandler::sendMessage(SocketHandler::connection_socket, com);
std::string men = com.send_to + "," + com.sent_from + "," + com.message;
std::cout << "First message sent (" << men << ")" << std::endl;
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 = "2";
com.sent_from = "1";
SocketHandler::sendMessage(SocketHandler::connection_socket, com);
std::cout << "Sent (" << com.message << ") to " << com.send_to << std::endl;
com = {"\0", "\0", "\0"};
}
}
}