Changeset 777 for code/branches/FICN/src/network/dummyclient.cc
- Timestamp:
- Dec 31, 2007, 7:40:23 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/FICN/src/network/dummyclient.cc
r514 r777 1 1 /* 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * 4 * 5 * License notice: 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 * Author: 22 * Oliver Scheuss, (C) 2007 23 * Co-authors: 24 * ... 25 * 26 */ 27 27 28 28 //o … … 34 34 #include <string> 35 35 #include <enet/enet.h> 36 37 #include "util/Sleep.h" 36 38 #include "PacketManager.h" 37 38 #ifdef WIN3239 #include <windows.h>40 #define usleep(x) Sleep((x)/1000)41 #else42 #include <unistd.h>43 #endif44 45 39 46 40 using namespace std; … … 66 60 address.port = 55556; 67 61 68 62 // create client object 69 63 client = enet_host_create(NULL, 2, 0, 0); 70 64 … … 73 67 exit(EXIT_FAILURE); 74 68 } 75 69 // connect peer 76 70 peer = enet_host_connect(client, &address, 2); 77 71 if(peer==NULL){ … … 79 73 exit(EXIT_FAILURE); 80 74 } 81 75 // wait 5 seconds for the connection attempt to succeed 82 76 if(enet_host_service(client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT){ 83 77 cout << "Connection to " << str << " succeeded." << endl; … … 91 85 92 86 for(int i=0; i<10; i++){ 93 87 // weihnachtsmann bringt packete 94 88 //ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE); 95 96 89 // extend the packet and append the string foo to it 90 // send packet to peer on channel id 0 97 91 enet_peer_send(peer, 1, pck.chatMessage("test2")); 98 92 // keep the timeout very small for low delay 99 93 if(enet_host_service(client, &event, 1)==0){ 100 94 cout << "successfully sent: " << event.type << endl; … … 105 99 } 106 100 107 108 // enet_peer_disconnect (peer);101 // now disconnect 102 // enet_peer_disconnect (peer); 109 103 enet_peer_disconnect (peer, 0); 110 104 // 3 seconds timeout 111 105 while(enet_host_service(client, &event, 3000) > 0){ 112 106 switch (event.type) 113 107 { 114 115 116 117 118 119 108 case ENET_EVENT_TYPE_RECEIVE: 109 enet_packet_destroy(event.packet); 110 break; 111 case ENET_EVENT_TYPE_DISCONNECT: 112 puts("Disconnection succeeded."); 113 return 0; 120 114 } 121 115 } 122 116 // if disconnect failed 123 117 enet_peer_reset(peer); 124 118
Note: See TracChangeset
for help on using the changeset viewer.