Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/network/dummyclient2.cc @ 893

Last change on this file since 893 was 790, checked in by nicolasc, 17 years ago

merged FICN back into trunk
awaiting release.

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