Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 31, 2007, 7:40:23 PM (16 years ago)
Author:
rgrieder
Message:
  • added dll support to the network library
  • improved header file dependency in network
File:
1 edited

Legend:

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

    r514 r777  
    11/*
    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  */
     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*/
    2727
    2828//o
     
    3434#include <string>
    3535#include <enet/enet.h>
     36
     37#include "util/Sleep.h"
    3638#include "PacketManager.h"
    37 
    38 #ifdef WIN32
    39 #include <windows.h>
    40 #define usleep(x) Sleep((x)/1000)
    41 #else
    42 #include <unistd.h>
    43 #endif
    44 
    4539
    4640using namespace std;
     
    6660  address.port = 55556;
    6761
    68         // create client object
     62  // create client object
    6963  client = enet_host_create(NULL, 2, 0, 0);
    7064
     
    7367    exit(EXIT_FAILURE);
    7468  }
    75         // connect peer
     69  // connect peer
    7670  peer = enet_host_connect(client, &address, 2);
    7771  if(peer==NULL){
     
    7973    exit(EXIT_FAILURE);
    8074  }
    81         // wait 5 seconds for the connection attempt to succeed
     75  // wait 5 seconds for the connection attempt to succeed
    8276  if(enet_host_service(client, &event, 5000) > 0 && event.type == ENET_EVENT_TYPE_CONNECT){
    8377    cout << "Connection to " << str << " succeeded." << endl;
     
    9185
    9286  for(int i=0; i<10; i++){
    93         // weihnachtsmann bringt packete
     87    // weihnachtsmann bringt packete
    9488    //ENetPacket *packet = enet_packet_create ("packet1234", strlen("packet1234") + 1, ENET_PACKET_FLAG_RELIABLE);
    95         // extend the packet and append the string foo to it
    96         // send packet to peer on channel id 0
     89    // extend the packet and append the string foo to it
     90    // send packet to peer on channel id 0
    9791    enet_peer_send(peer, 1, pck.chatMessage("test2"));
    98         // keep the timeout very small for low delay
     92    // keep the timeout very small for low delay
    9993    if(enet_host_service(client, &event, 1)==0){
    10094      cout << "successfully sent: " << event.type << endl;
     
    10599  }
    106100
    107         // now disconnect
    108 //   enet_peer_disconnect (peer);
     101  // now disconnect
     102  //   enet_peer_disconnect (peer);
    109103  enet_peer_disconnect (peer, 0);
    110         // 3 seconds timeout
     104  // 3 seconds timeout
    111105  while(enet_host_service(client, &event, 3000) > 0){
    112106    switch (event.type)
    113107    {
    114       case ENET_EVENT_TYPE_RECEIVE:
    115         enet_packet_destroy(event.packet);
    116         break;
    117       case ENET_EVENT_TYPE_DISCONNECT:
    118         puts("Disconnection succeeded.");
    119         return 0;
     108    case ENET_EVENT_TYPE_RECEIVE:
     109      enet_packet_destroy(event.packet);
     110      break;
     111    case ENET_EVENT_TYPE_DISCONNECT:
     112      puts("Disconnection succeeded.");
     113      return 0;
    120114    }
    121115  }
    122         // if disconnect failed
     116  // if disconnect failed
    123117  enet_peer_reset(peer);
    124118
Note: See TracChangeset for help on using the changeset viewer.