src/network/l3_demo.cpp File Reference

#include "config.h"
#include "tSafePTR.h"
#include <string>
#include <iostream>
#include "nNetObject.h"

Include dependency graph for l3_demo.cpp:

Go to the source code of this file.

Classes

class  floattest
class  deptest

Functions

void server ()
void client (const tString &serv)
int main (int argnum, char **arglist)

Variables

nNOInitialisator< floattestfloattest_init (100,"floattest")
nNOInitialisator< deptestdeptest_init (101,"deptest")
unsigned short client_gamestate [MAXCLIENTS+2]


Function Documentation

void client ( const tString serv  ) 

Definition at line 209 of file l3_demo.cpp.

References con, deptest::deptest(), nSTANDALONE, sn_Connect(), sn_GetNetState(), sn_Receive(), sn_SendPlanned(), sn_SetNetState(), nNetObject::SyncAll(), deptest::tCONTROLLED_PTR(), and x.

00209                                 {
00210     tCONTROLLED_PTR(floattest) x=new floattest();
00211     tCONTROLLED_PTR(deptest)   y=new deptest(x);
00212 
00213     sn_Connect(serv); // initialise client state and connect to the given server
00214 
00215     con << "Demo 1: transfering state by sync messages\n";
00216 
00217     int loop=10; // loop only shortly
00218     while(loop>0 && sn_GetNetState()!=nSTANDALONE){
00219         nNetObject::SyncAll();
00220         sn_Receive();
00221 
00222         // change x's state and request a sync with the server
00223         con << "new state: " << (x->x+=1) << "\n";
00224         x->RequestSync();
00225 
00226         nNetObject::SyncAll();
00227         sn_SendPlanned();
00228         sn_Receive();
00229         sn_SendPlanned();
00230 
00231         loop--;
00232         usleep(1000000);
00233     }
00234 
00235     if (loop==0){
00236 
00237         con << "Demo 2: sending control messages. Note the delay in the response\n"
00238         << "caused by the network loop functions not beeing called "
00239         "often enough.\n";
00240 
00241 
00242         loop=10;
00243         while(loop>0 && sn_GetNetState()!=nSTANDALONE){
00244             nNetObject::SyncAll();
00245             sn_Receive();
00246 
00247             // send a control message, decreasing x's value
00248             x->SendControl(-1);
00249 
00250             nNetObject::SyncAll();
00251             sn_Receive();
00252             sn_SendPlanned();
00253 
00254             loop--;
00255             usleep(1000000);
00256         }
00257 
00258         // get rest of messages
00259         loop=100;
00260         while(loop>0 && sn_GetNetState()!=nSTANDALONE){
00261             sn_Receive();
00262             nNetObject::SyncAll();
00263             sn_SendPlanned();
00264 
00265             loop--;
00266             usleep(1000);
00267         }
00268     }
00269 
00270     if (loop==0)
00271         con << "Regular logout..\n";
00272 
00273     sn_SetNetState(nSTANDALONE);
00274     usleep(100000);
00275     sn_Receive();
00276     sn_SendPlanned();
00277 }

Here is the call graph for this function:

int main ( int  argnum,
char **  arglist 
)

Definition at line 281 of file l3_demo.cpp.

References client(), and server().

00281                                    {
00282     if (argnum<=1){
00283         server();
00284     }
00285     else{
00286         client(arglist[1]);
00287     }
00288 }

Here is the call graph for this function:

void server (  ) 

Definition at line 187 of file l3_demo.cpp.

References nSERVER, nSTANDALONE, sn_GetNetState(), sn_Receive(), sn_SendPlanned(), sn_SetNetState(), and nNetObject::SyncAll().

00187              {
00188 
00189     int loop=100000; // a long delay loop
00190 
00191     sn_SetNetState(nSERVER); // initialise server mode
00192 
00193     while(loop>0 && sn_GetNetState()!=nSTANDALONE){ // and loop a while
00194         sn_Receive();
00195         nNetObject::SyncAll();
00196         sn_SendPlanned();
00197 
00198         loop--;
00199         usleep(10000);
00200     }
00201 
00202     sn_SetNetState(nSTANDALONE); // exit.
00203     usleep(10000);
00204     sn_Receive();
00205     sn_SendPlanned();
00206 }

Here is the call graph for this function:


Variable Documentation

unsigned short client_gamestate[MAXCLIENTS+2]

Definition at line 185 of file l3_demo.cpp.

nNOInitialisator<deptest> deptest_init(101,"deptest")

Referenced by deptest::CreatorDescriptor().

nNOInitialisator<floattest> floattest_init(100,"floattest")

Referenced by floattest::CreatorDescriptor().


Generated on Sat Mar 15 23:00:13 2008 for Armagetron Advanced by  doxygen 1.5.4