Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 31, 2008, 11:24:44 PM (16 years ago)
Author:
rgrieder
Message:
  • set the svn:eol-style property to all files so, that where ever you check out, you'll get the right line endings (had to change every file with mixed endings to windows in order to set the property)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/dummyclient.cc

    • Property svn:eol-style set to native
    r1293 r1494  
    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 //o
    30 // Dummy client to test ConnectionManager and PacketBuffer 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 
    42 using namespace std;
    43 
    44 int main(){
    45   ENetHost * client;
    46   ENetAddress address;
    47   ENetEvent event;
    48   ENetPeer *peer;
    49   network::PacketGenerator pck;
    50 
    51   enet_initialize();
    52   atexit(enet_deinitialize);
    53 
    54   cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << endl;
    55   string str;
    56   getline(cin, str);
    57   cout << "You entered: " << str << endl;
    58   if(str.compare("")==0)
    59     str="127.0.0.1";
    60 
    61   enet_address_set_host(&address, str.c_str());
    62   address.port = 55556;
    63 
    64   // create client object
    65   client = enet_host_create(NULL, 2, 0, 0);
    66 
    67   if(client==NULL){
    68     fprintf(stderr, "An error occured");
    69     exit(EXIT_FAILURE);
    70   }
    71   // connect peer
    72   peer = enet_host_connect(client, &address, 2);
    73   if(peer==NULL){
    74     fprintf(stderr, "Peer establishing error");
    75     exit(EXIT_FAILURE);
    76   }
    77   // wait 5 seconds for the connection attempt to succeed
    78   if(enet_host_service(client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT){
    79     cout << "Connection to " << str << " succeeded." << endl;
    80     //puts("Connection to localhost:5555 succeeded.");
    81   }else{
    82     enet_peer_reset(peer);
    83     cout << "Connection to " << str << " failed." << endl;
    84     //puts("Connection to localhost:5555 failed.");
    85     exit(EXIT_FAILURE);
    86   }
    87 
    88   for(int i=0; i<10; i++){
    89     // weihnachtsmann bringt packete
    90     //ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE);
    91     // extend the packet and append the string foo to it
    92     // send packet to peer on channel id 0
    93     enet_peer_send(peer, 1, pck.chatMessage("test2"));
    94     // keep the timeout very small for low delay
    95     if(enet_host_service(client, &event, 1)==0){
    96       cout << "successfully sent: " << event.type << endl;
    97     }else{
    98       cout << "failed sending" << endl;
    99     }
    100     usleep(1000000);
    101   }
    102 
    103   // now disconnect
    104   //   enet_peer_disconnect (peer);
    105   enet_peer_disconnect (peer, 0);
    106   // 3 seconds timeout
    107   while(enet_host_service(client, &event, 3000) > 0){
    108     switch (event.type)
    109     {
    110     case ENET_EVENT_TYPE_RECEIVE:
    111       enet_packet_destroy(event.packet);
    112       break;
    113     case ENET_EVENT_TYPE_DISCONNECT:
    114       puts("Disconnection succeeded.");
    115       return 0;
    116     }
    117   }
    118   // if disconnect failed
    119   enet_peer_reset(peer);
    120 
    121 
    122 
    123   return 0;
    124 }
     1/* *   ORXONOX - the hottest 3D action shooter ever to exist *                    > www.orxonox.net < * * *   License notice: * *   This program is free software; you can redistribute it and/or *   modify it under the terms of the GNU General Public License *   as published by the Free Software Foundation; either version 2 *   of the License, or (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. * *   Author: *      Oliver Scheuss, (C) 2007 *   Co-authors: *      ... * *///o// Dummy client to test ConnectionManager and PacketBuffer classes//// Author: Oliver Scheuss#include <iostream>#include <string>#include <enet/enet.h>#include "util/Sleep.h"#include "PacketManager.h"#include "PacketTypes.h"
     2using namespace std;int main(){  ENetHost * client;  ENetAddress address;  ENetEvent event;  ENetPeer *peer;  network::PacketGenerator pck;  enet_initialize();  atexit(enet_deinitialize);  cout << "Enter address of the server xxx.xxx.xxx.xxx (enter for localhost)" << endl;  string str;  getline(cin, str);  cout << "You entered: " << str << endl;  if(str.compare("")==0)    str="127.0.0.1";  enet_address_set_host(&address, str.c_str());  address.port = 55556;  // create client object  client = enet_host_create(NULL, 2, 0, 0);  if(client==NULL){    fprintf(stderr, "An error occured");    exit(EXIT_FAILURE);  }  // connect peer  peer = enet_host_connect(client, &address, 2);  if(peer==NULL){    fprintf(stderr, "Peer establishing error");    exit(EXIT_FAILURE);  }  // wait 5 seconds for the connection attempt to succeed  if(enet_host_service(client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT){    cout << "Connection to " << str << " succeeded." << endl;    //puts("Connection to localhost:5555 succeeded.");  }else{    enet_peer_reset(peer);    cout << "Connection to " << str << " failed." << endl;    //puts("Connection to localhost:5555 failed.");    exit(EXIT_FAILURE);  }  for(int i=0; i<10; i++){    // weihnachtsmann bringt packete    //ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE);    // extend the packet and append the string foo to it    // send packet to peer on channel id 0    enet_peer_send(peer, 1, pck.chatMessage("test2"));    // keep the timeout very small for low delay    if(enet_host_service(client, &event, 1)==0){      cout << "successfully sent: " << event.type << endl;    }else{      cout << "failed sending" << endl;    }    usleep(1000000);  }  // now disconnect  //   enet_peer_disconnect (peer);  enet_peer_disconnect (peer, 0);  // 3 seconds timeout  while(enet_host_service(client, &event, 3000) > 0){    switch (event.type)    {    case ENET_EVENT_TYPE_RECEIVE:      enet_packet_destroy(event.packet);      break;    case ENET_EVENT_TYPE_DISCONNECT:      puts("Disconnection succeeded.");      return 0;    }  }  // if disconnect failed  enet_peer_reset(peer);  return 0;}
Note: See TracChangeset for help on using the changeset viewer.