Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/FICN/src/network/dummyclient2.cc @ 515

Last change on this file since 515 was 514, checked in by nicolasc, 17 years ago

added copyright notice

File size: 2.4 KB
Line 
1/*
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
28//
29// Dummy client to test ConnectionManager, PacketBuffer, ClientConnection and other classes
30//
31// Author: Oliver Scheuss
32
33#include <iostream>
34#include <string>
35#include <enet/enet.h>
36#include "PacketManager.h"
37#include "ClientConnection.h"
38
39using namespace network;
40
41int main(){
42  network::PacketGenerator pck;
43
44  std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
45  std::string str;
46  std::getline(std::cin, str);
47  std::cout << "You entered: " << str << std::endl;
48  if(str.compare("")==0)
49    str="127.0.0.1";
50
51  ClientConnection client = ClientConnection(55556, str);
52
53  client.createConnection();
54
55  if(client.waitEstablished(10000))
56    std::cout << "Connection established" << std::endl;
57  else
58    std::cout << "Connection failed" << std::endl;
59
60  ENetPacket *packet;
61  ENetEvent event;
62
63
64
65  for(int i=0; i<10; i++){
66        // weihnachtsmann bringt packete
67        // extend the packet and append the string foo to it
68        // send packet to peer on channel id 0
69    client.addPacket(pck.chatMessage("test"));
70        // keep the timeout very small for low delay
71    if(client.sendPackets(&event)){
72      std::cout << "successfully sent: " << event.type << std::endl;
73    }else{
74      std::cout << "failed sending" << std::endl;
75    }
76//    usleep(1000000);
77  }
78  usleep(1000000);
79        // now disconnect
80  if(client.closeConnection())
81    std::cout << "Connection successfully closed" << std::endl;
82  else
83    std::cout << "Connection closing failed" << std::endl;
84
85        // 3 seconds timeout
86  return 0;
87}
88
Note: See TracBrowser for help on using the repository browser.