The GameNet module (GNet for short) provides a set of commands for creating and managing multiplayer network games.
GNet works a little differently than other networking libraries. Instead of being primarily 'message based', GNet works by synchronizing a collection of GNet objects over a network.
Each GNet object contains 32 &slots which are similar in nature to the fields of BlitzMax objects. You can write to these slots using the SetGNetInt, SetGNetFloat and SetGNetString commands, and read from these slots using the GetGNetInt, GetGNetFloat and GetGNetString commands. The actual meaning of the data contained in these slots is completely up to you, but will typically include such information as player position, score, hitpoints and so on.
Note that you can only modify GNet objects that you have yourself created. Such objects are known as local objects, while objects created elsewhere are known as remote objects.
To start using GNet, you must first create a GNet host with the CreateGNetHost command. Once you have created a host, you can either connect to other GNet hosts using GNetConnect, or prepare to accept connections from other hosts using GNetListen.
The GNetSync command brings all GNet objects up to date. This involves notifying other hosts about any modifications you have made to local GNet objects, and processing notifications from other hosts about any modifications to remote GNet objects.
GNet also provides a simple messaging system. A GNet message is actually just a special type of GNet object, so you initialize messages using the standard GNet commands for writing slots. Once created and initialized, a message can be sent to a remote object using the SendGNetMessage command.
Incoming messages can be processed using the GNetMessages command after a GNetSync. This function returns a linked list of messages objects which can be examined using the standard GNet commands for reading slots. In addition, the GNetMessageObject command can be used to determine which local object a message was intended for.
Create GNet host
A new GNet host
Function CloseGNetHost( host:TGNetHost )
Close a GNet host
Once closed, a GNet host cannot be reopened.
Function GNetSync( host:TGNetHost )
Synchronize GNet host
Function GNetListen( host:TGNetHost,port )
Listen for connections
Causes host to start listening for connection attempts on the specified port. Once a host is listening, hosts on other machines can connect using GNetConnect.
True if successful, otherwise false
Function GNetConnect( host:TGNetHost,address$,port,timeout_ms=10000 )
Connect to a remote GNet host
Attempts to connect host to the specified remote address and port.
A GNet host must be listening (see GNetListen) at the specified address and port for the connection to succeed.
True if connection successful, otherwise false
Function GNetObjects:TList( host:TGNetHost,state=GNET_ALL )
Get a list of GNet objects
GNetObjects returns a list of GNet objects in a certain state.
The state parameter controls which objects are listed, and can be one of &GNET_ALL, &GNET_CREATED, &GNET_MODIFIED or &GNET_CLOSED.
Note that with the exception of &GNET_ALL, the returned lists will only ever contain remote objects.
A linked list
Function GNetMessages:TList( host:TGNetHost )
Get a list of GNet messages sent to local objects
A linked list
Function CreateGNetObject:TGNetObject( host:TGNetHost )
Create a GNet object
A new GNet object
Function CreateGNetMessage:TGNetObject( host:TGNetHost )
Create a GNet message object
A new GNet object
Function SendGNetMessage( msg:TGNetObject,toObject:TGNetObject )
Send a GNet message to a remote object
Function GNetMessageObject:TGNetObject( msg:TGNetObject )
Get message target object
The object that msg was sent to
Function GNetObjectState( obj:TGNetObject )
Get state of a GNet object
The returned value can be one of the following:
|GNET_CREATED||Object has been created|
|GNET_SYNCED||Object is in sync|
|GNET_MODIFIED||Object has been modified|
|GNET_CLOSED||Object has been closed|
|GNET_ZOMBIE||Object is a zombie|
|GNET_MESSAGE||Object is a message object|
An integer state
Function GNetObjectLocal( obj:TGNetObject )
Determine whether a GNet object is local
True if object is a local object
Function GNetObjectRemote( obj:TGNetObject )
Determine whether a GNet object is remote
True if object is a remote object
Function SetGNetInt( obj:TGNetObject,index,value )
Set GNet object int data
Function SetGNetFloat( obj:TGNetObject,index,value# )
Set GNet object float data
Function SetGNetString( obj:TGNetObject,index,value$ )
Set GNet object string data
Function GetGNetInt( obj:TGNetObject,index )
Get GNet object int data
Function GetGNetFloat#( obj:TGNetObject,index )
Get GNet object float data
Function GetGNetString$( obj:TGNetObject,index )
Get GNet object string data
Function SetGNetTarget( obj:TGNetObject,target:Object )
Set a GNet object's target object
This command allows you to bind an abitrary object to a GNet object.
Function GetGNetTarget:Object( obj:TGNetObject )
Get a GNet object's target object
The currently bound target object
Function CloseGNetObject( obj:TGNetObject )
Close a GNet object