RemoteVariables!

Posted: 30th May 2012 by Ammar Qammaz in Post
Tags:

During the last weeks I finally found time to work on one of my older ideas ( 2 years old :P ) about a networking library that wouldn’t expose any network calls to the programmer..!

From my experience writing small games and web server services network connectivity using sockets is very nice and efficient indeed , but it has a lot of programming overhead to basically do simple things like passing values or strings from one host to the other..

With RemoteVariables what I am doing is writing a framework that takes care of all the protocol issues and then assumes the role of synchronizing specific elements of the address space of the first computer to the second one..!

So instead of recv/send ing , worrying about half read messages or making a new mini wrapper protocol for every new application the idea goes like this ..

/* CLIENT CODE */
struct VariableShare * vsh = ConnectToRemote_VariableSharing(“SHARE2″,”127.0.0.1″,12345,”password”);
static volatile int SHARED_VAR=0; Add_VariableToSharingList(vsh,”SHARED_VAR”,7,&SHARED_VAR,sizeof(SHARED_VAR));

/* SERVER CODE*/
struct VariableShare * vsh = Start_VariableSharing(“SHARE2″,”127.0.0.1″,12345,”password”);
static volatile int SHARED_VAR=0;
Add_VariableToSharingList(vsh,”SHARED_VAR”,7,&SHARED_VAR,sizeof(SHARED_VAR));

from there on variable SHARED_VAR is “shared” meaning that when it changes on one host we know that the second host will get it.
The change is “sensed” by a second thread monitoring the values of the address space and transmiting them when they change.. It could be the case that the compiler could spit in a Sync(&SHARED_VAR) operation after each change for maximum efficiency .. Some one can also disable automatic “sensing” and perform the Sync call manually to avoid the overheads of the extra thread on the background..

Another example is for lets say a Tic Tac Toe game where we will have
/* CLIENT CODE */
struct VariableShare * vsh = ConnectToRemote_VariableSharing(“TICSHARE”,”127.0.0.1″,12345,”password”);
static volatile int OURMOVE=0,OPPONENTMOVE=0;
Add_VariableToSharingList(vsh,”HOST_MOVE”,7,&OPPONENTMOVE,sizeof(OPPONENTMOVE));
Add_VariableToSharingList(vsh,”SHARED_VAR”,7,&OURMOVE,sizeof(OURMOVE));

/* SERVER CODE */
struct VariableShare * vsh = Start_VariableSharing(“TICSHARE”,”127.0.0.1″,12345,”password”);
static volatile int OURMOVE=0,OPPONENTMOVE=0;
Add_VariableToSharingList(vsh,”SHARED_VAR”,7,&OPPONENTMOVE,sizeof(OPPONENTMOVE));
Add_VariableToSharingList(vsh,”HOST_MOVE”,7,&OURMOVE,sizeof(OURMOVE));

Notice the twisted assignment of the SHARED_VAR , HOST_MOVE ..
This way we could litterally write a network tictac toe program by just checking the OURMOVE , OPPONENTMOVE variables just like writing a two player hot seat game , no more extra code , maybe just for checking if the Client has dropped something that doesnt really happen on hot seat games ..

Needless to say its not over yet but I am making good progress..

The Repository is here ( https://github.com/AmmarkoV/RemoteVariable )..

To test it issue :
git clone git://github.com/AmmarkoV/RemoteVariable.git
./apt-get-dependencies.sh
./make
and you can then test a Score4 Game by issuing
./TestGameMasterAndClone.sh

or test the standalone library via a unit test by issuing
./TestMasterAndClone.sh
of
./MemTestMasterAndClone.sh
for valgrind analysis too..

Comments are closed.