[438] | 1 | #include <iostream> |
---|
| 2 | #include <string> |
---|
[777] | 3 | |
---|
| 4 | #include "util/Sleep.h" |
---|
[438] | 5 | #include "PacketManager.h" |
---|
[781] | 6 | #include "PacketTypes.h" |
---|
[438] | 7 | #include "Client.h" |
---|
| 8 | |
---|
| 9 | using namespace network; |
---|
| 10 | |
---|
[448] | 11 | void sender(){ |
---|
| 12 | |
---|
[438] | 13 | network::PacketGenerator pck; |
---|
[441] | 14 | const int PORT = 55556; |
---|
[438] | 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"; |
---|
[448] | 21 | |
---|
[438] | 22 | Client client( str, PORT ); |
---|
| 23 | if ( client.establishConnection() ) |
---|
[777] | 24 | std::cout << "connection established" << std::endl; |
---|
[441] | 25 | else std::cout << "problems establishing connection" << std::endl; |
---|
[632] | 26 | char message[10000]; |
---|
| 27 | char signs[] = "abcdefghijklmnopqrstuvwxy"; |
---|
[438] | 28 | while (true) { |
---|
[777] | 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(); |
---|
[438] | 40 | } |
---|
[448] | 41 | |
---|
| 42 | |
---|
| 43 | |
---|
[441] | 44 | } |
---|
[448] | 45 | |
---|
| 46 | void listener(){ |
---|
[777] | 47 | |
---|
[448] | 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() ) |
---|
[777] | 58 | std::cout << "connection established" << std::endl; |
---|
[448] | 59 | else std::cout << "problems establishing connection" << std::endl; |
---|
| 60 | |
---|
| 61 | while (true) { |
---|
[777] | 62 | client.tick(0); |
---|
| 63 | usleep(100); |
---|
[448] | 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 | } |
---|