[1056] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * ... |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[438] | 29 | #include <iostream> |
---|
| 30 | #include <string> |
---|
[777] | 31 | |
---|
| 32 | #include "util/Sleep.h" |
---|
[438] | 33 | #include "PacketManager.h" |
---|
[781] | 34 | #include "PacketTypes.h" |
---|
[438] | 35 | #include "Client.h" |
---|
| 36 | |
---|
| 37 | using namespace network; |
---|
| 38 | |
---|
[448] | 39 | void sender(){ |
---|
| 40 | |
---|
[438] | 41 | network::PacketGenerator pck; |
---|
[441] | 42 | const int PORT = 55556; |
---|
[1021] | 43 | COUT(0) << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl; |
---|
[438] | 44 | std::string str; |
---|
| 45 | std::getline(std::cin, str); |
---|
[1021] | 46 | COUT(3) << "You entered: " << str << std::endl; |
---|
[438] | 47 | if(str.compare("")==0) |
---|
| 48 | str="127.0.0.1"; |
---|
[448] | 49 | |
---|
[438] | 50 | Client client( str, PORT ); |
---|
| 51 | if ( client.establishConnection() ) |
---|
[1021] | 52 | COUT(3) << "connection established" << std::endl; |
---|
| 53 | else COUT(0) << "problems establishing connection" << std::endl; |
---|
[632] | 54 | char message[10000]; |
---|
| 55 | char signs[] = "abcdefghijklmnopqrstuvwxy"; |
---|
[438] | 56 | while (true) { |
---|
[777] | 57 | client.tick(0); |
---|
| 58 | |
---|
| 59 | std::cout << "your message2: "; |
---|
| 60 | for ( int i=0; i<9999; i++ ) { |
---|
| 61 | message[i] = signs[0]; |
---|
| 62 | } |
---|
| 63 | message[9999] = 'z'; |
---|
| 64 | std::string str( message ); |
---|
| 65 | client.sendChat( str ); |
---|
| 66 | std::cout << str << std::endl; |
---|
| 67 | std::cin.get(); std::cin.get(); |
---|
[438] | 68 | } |
---|
[448] | 69 | |
---|
| 70 | |
---|
| 71 | |
---|
[441] | 72 | } |
---|
[448] | 73 | |
---|
| 74 | void listener(){ |
---|
[777] | 75 | |
---|
[448] | 76 | const int PORT = 55556; |
---|
| 77 | std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl; |
---|
| 78 | std::string str; |
---|
| 79 | std::getline(std::cin, str); |
---|
| 80 | std::cout << "You entered: " << str << std::endl; |
---|
| 81 | if(str.compare("")==0) |
---|
| 82 | str="127.0.0.1"; |
---|
| 83 | |
---|
| 84 | Client client( str, PORT ); |
---|
| 85 | if ( client.establishConnection() ) |
---|
[777] | 86 | std::cout << "connection established" << std::endl; |
---|
[448] | 87 | else std::cout << "problems establishing connection" << std::endl; |
---|
| 88 | |
---|
| 89 | while (true) { |
---|
[777] | 90 | client.tick(0); |
---|
| 91 | usleep(100); |
---|
[448] | 92 | } |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | |
---|
| 99 | int main(int argc, char **argv[]){ |
---|
| 100 | std::string in; |
---|
| 101 | std::cout << "Please choose: sender(s) oder listener(l)" << std::endl; |
---|
| 102 | std::getline(std::cin, in); |
---|
| 103 | if(in.compare("l")==0) |
---|
| 104 | listener(); |
---|
| 105 | else if(in.compare("s")==0) |
---|
| 106 | sender(); |
---|
| 107 | else |
---|
| 108 | std::cout << "wrong answer" << std::endl; |
---|
| 109 | } |
---|