Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/archive/shader/src/network/dummyclient2.cc @ 10634

Last change on this file since 10634 was 1505, checked in by rgrieder, 17 years ago

f* svn: It doesn't even inform you if you attempt to set a non existing property. It is svn:eol-style and not eol-style when using the command by the way…

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