[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 | |
---|
[1062] | 29 | #include "Client.h" |
---|
| 30 | |
---|
[438] | 31 | #include <iostream> |
---|
| 32 | #include <string> |
---|
[777] | 33 | |
---|
| 34 | #include "util/Sleep.h" |
---|
[438] | 35 | #include "PacketManager.h" |
---|
[781] | 36 | #include "PacketTypes.h" |
---|
[438] | 37 | |
---|
| 38 | using namespace network; |
---|
| 39 | |
---|
[448] | 40 | void sender(){ |
---|
| 41 | |
---|
[438] | 42 | network::PacketGenerator pck; |
---|
[441] | 43 | const int PORT = 55556; |
---|
[1021] | 44 | COUT(0) << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl; |
---|
[438] | 45 | std::string str; |
---|
| 46 | std::getline(std::cin, str); |
---|
[1021] | 47 | COUT(3) << "You entered: " << str << std::endl; |
---|
[438] | 48 | if(str.compare("")==0) |
---|
| 49 | str="127.0.0.1"; |
---|
[448] | 50 | |
---|
[438] | 51 | Client client( str, PORT ); |
---|
| 52 | if ( client.establishConnection() ) |
---|
[1021] | 53 | COUT(3) << "connection established" << std::endl; |
---|
| 54 | else COUT(0) << "problems establishing connection" << std::endl; |
---|
[632] | 55 | char message[10000]; |
---|
| 56 | char signs[] = "abcdefghijklmnopqrstuvwxy"; |
---|
[438] | 57 | while (true) { |
---|
[777] | 58 | client.tick(0); |
---|
| 59 | |
---|
| 60 | std::cout << "your message2: "; |
---|
| 61 | for ( int i=0; i<9999; i++ ) { |
---|
| 62 | message[i] = signs[0]; |
---|
| 63 | } |
---|
| 64 | message[9999] = 'z'; |
---|
| 65 | std::string str( message ); |
---|
| 66 | client.sendChat( str ); |
---|
| 67 | std::cout << str << std::endl; |
---|
| 68 | std::cin.get(); std::cin.get(); |
---|
[438] | 69 | } |
---|
[448] | 70 | |
---|
| 71 | |
---|
| 72 | |
---|
[441] | 73 | } |
---|
[448] | 74 | |
---|
| 75 | void listener(){ |
---|
[777] | 76 | |
---|
[448] | 77 | const int PORT = 55556; |
---|
| 78 | std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl; |
---|
| 79 | std::string str; |
---|
| 80 | std::getline(std::cin, str); |
---|
| 81 | std::cout << "You entered: " << str << std::endl; |
---|
| 82 | if(str.compare("")==0) |
---|
| 83 | str="127.0.0.1"; |
---|
| 84 | |
---|
| 85 | Client client( str, PORT ); |
---|
| 86 | if ( client.establishConnection() ) |
---|
[777] | 87 | std::cout << "connection established" << std::endl; |
---|
[448] | 88 | else std::cout << "problems establishing connection" << std::endl; |
---|
| 89 | |
---|
| 90 | while (true) { |
---|
[777] | 91 | client.tick(0); |
---|
| 92 | usleep(100); |
---|
[448] | 93 | } |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | int main(int argc, char **argv[]){ |
---|
| 101 | std::string in; |
---|
| 102 | std::cout << "Please choose: sender(s) oder listener(l)" << std::endl; |
---|
| 103 | std::getline(std::cin, in); |
---|
| 104 | if(in.compare("l")==0) |
---|
| 105 | listener(); |
---|
| 106 | else if(in.compare("s")==0) |
---|
| 107 | sender(); |
---|
| 108 | else |
---|
| 109 | std::cout << "wrong answer" << std::endl; |
---|
| 110 | } |
---|