Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 777 was 777, checked in by rgrieder, 16 years ago
  • added dll support to the network library
  • improved header file dependency in network
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
37#include "util/Sleep.h"
38#include "PacketManager.h"
39#include "ClientConnection.h"
40
41using namespace network;
42
43int main(){
44  network::PacketGenerator pck;
45
46  std::cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << std::endl;
47  std::string str;
48  std::getline(std::cin, str);
49  std::cout << "You entered: " << str << std::endl;
50  if(str.compare("")==0)
51    str="127.0.0.1";
52
53  ClientConnection client = ClientConnection(55556, str);
54
55  client.createConnection();
56
57  if(client.waitEstablished(10000))
58    std::cout << "Connection established" << std::endl;
59  else
60    std::cout << "Connection failed" << std::endl;
61
62  ENetPacket *packet;  //FIXME: unused var!
63  ENetEvent event;
64
65
66
67  for(int i=0; i<10; i++){
68    // weihnachtsmann bringt packete
69    // extend the packet and append the string foo to it
70    // send packet to peer on channel id 0
71    client.addPacket(pck.chatMessage("test"));
72    // keep the timeout very small for low delay
73    if(client.sendPackets(&event)){
74      std::cout << "successfully sent: " << event.type << std::endl;
75    }else{
76      std::cout << "failed sending" << std::endl;
77    }
78    //    usleep(1000000);
79  }
80  usleep(1000000);
81  // now disconnect
82  if(client.closeConnection())
83    std::cout << "Connection successfully closed" << std::endl;
84  else
85    std::cout << "Connection closing failed" << std::endl;
86
87  // 3 seconds timeout
88  return 0;
89}
90
Note: See TracBrowser for help on using the repository browser.