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