-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.cpp
55 lines (39 loc) · 848 Bytes
/
client.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "Common/Common.hpp"
#include "UDP/UDP.hpp"
int Application::main(){
console->clear();
String host;
int port;
host = (String) in->put("Informe o servidor [127.0.0.1]: ");
if(host.empty()){
host.append("127.0.0.1");
}
port = in->put("Informe a porta: ");
UdpClient connection(host, port);
out->put("Conectando...", true);
if(!connection.openSocket()){
out->put("Falha ao conectar.", true);
return 0;
}
if(!connection.send("help")){
out->put("Falha ao conectar.", true);
return 0;
}
String input;
String output;
while(true){
output.clear();
input.clear();
connection.recieve(output);
out->put(" -> ")->put(output, true);
input = (String) in->put("Comando: ");
if(input.compare("exit") == 0){
break;
}
else{
connection.send(input);
}
}
connection.closeSocket();
return 0;
}