1 | #include <iostream> |
---|
2 | #include <string> |
---|
3 | |
---|
4 | #include "util/Sleep.h" |
---|
5 | #include "PacketManager.h" |
---|
6 | #include "PacketTypes.h" |
---|
7 | #include "Client.h" |
---|
8 | |
---|
9 | using namespace network; |
---|
10 | |
---|
11 | void sender(){ |
---|
12 | |
---|
13 | network::PacketGenerator pck; |
---|
14 | const int PORT = 55556; |
---|
15 | std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl; |
---|
16 | std::string str; |
---|
17 | std::getline(std::cin, str); |
---|
18 | std::cout << "You entered: " << str << std::endl; |
---|
19 | if(str.compare("")==0) |
---|
20 | str="127.0.0.1"; |
---|
21 | |
---|
22 | Client client( str, PORT ); |
---|
23 | if ( client.establishConnection() ) |
---|
24 | std::cout << "connection established" << std::endl; |
---|
25 | else std::cout << "problems establishing connection" << std::endl; |
---|
26 | char message[10000]; |
---|
27 | char signs[] = "abcdefghijklmnopqrstuvwxy"; |
---|
28 | while (true) { |
---|
29 | client.tick(0); |
---|
30 | |
---|
31 | std::cout << "your message2: "; |
---|
32 | for ( int i=0; i<9999; i++ ) { |
---|
33 | message[i] = signs[0]; |
---|
34 | } |
---|
35 | message[9999] = 'z'; |
---|
36 | std::string str( message ); |
---|
37 | client.sendChat( str ); |
---|
38 | std::cout << str << std::endl; |
---|
39 | std::cin.get(); std::cin.get(); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | } |
---|
45 | |
---|
46 | void listener(){ |
---|
47 | |
---|
48 | const int PORT = 55556; |
---|
49 | std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl; |
---|
50 | std::string str; |
---|
51 | std::getline(std::cin, str); |
---|
52 | std::cout << "You entered: " << str << std::endl; |
---|
53 | if(str.compare("")==0) |
---|
54 | str="127.0.0.1"; |
---|
55 | |
---|
56 | Client client( str, PORT ); |
---|
57 | if ( client.establishConnection() ) |
---|
58 | std::cout << "connection established" << std::endl; |
---|
59 | else std::cout << "problems establishing connection" << std::endl; |
---|
60 | |
---|
61 | while (true) { |
---|
62 | client.tick(0); |
---|
63 | usleep(100); |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | int main(int argc, char **argv[]){ |
---|
72 | std::string in; |
---|
73 | std::cout << "Please choose: sender(s) oder listener(l)" << std::endl; |
---|
74 | std::getline(std::cin, in); |
---|
75 | if(in.compare("l")==0) |
---|
76 | listener(); |
---|
77 | else if(in.compare("s")==0) |
---|
78 | sender(); |
---|
79 | else |
---|
80 | std::cout << "wrong answer" << std::endl; |
---|
81 | } |
---|