CRM64Pro GDK v0.11.0
A free cross-platform game development kit built on top of SDL 3.0
|
v1.00 (1 May 2023)
The Network TCP/IP interface provides a complete network system based on TCP/IP client/server architecture.
It is based on CRM32Pro INetwork code with several code parts reworked from scratch and others being heavily improved.
Main features:
Only a single instance of the Network TCP/IP interface exists which is created once Main is instantiated.
You can get a reference to this manager using Main::INetTCP() method.
Classes | |
class | CRM64Pro::NetTCP |
NetTCP class. More... | |
Macros | |
#define | NETFEATURE_DISABLE_LOGIN 1 |
Enumerations | |
enum | CRM64Pro::eNetMsg { CRM64Pro::NETMSG_NOTHING = 0 , CRM64Pro::NETMSG_DATA = 64 , CRM64Pro::NETMSG_DATA_ACCEPTED = 66 , CRM64Pro::NETMSG_DATA_DENIED = 67 , CRM64Pro::NETMSG_NEWCLIENT = 132 , CRM64Pro::NETMSG_QUITCLIENT = 133 , CRM64Pro::NETMSG_CLOSE = 134 , CRM64Pro::NETMSG_INFO = 135 , CRM64Pro::NETMSG_PING = 136 , CRM64Pro::NETMSG_ERROR = 192 } |
Network messages. More... | |
Functions | |
Sint32 | CRM64Pro::NetTCP::info (Sint32 iMode=0) |
Request NetTCP Interface information. | |
Sint32 | CRM64Pro::NetTCP::init (Uint8 iLM) |
Initialize the NetTCP system. | |
Sint32 | CRM64Pro::NetTCP::close () |
Close the NetTCP system. | |
Sint32 | CRM64Pro::NetTCP::isServer () |
Check if the server is running. | |
Sint32 | CRM64Pro::NetTCP::isClient () |
Check if the client is running. | |
Uint32 | CRM64Pro::NetTCP::getIP () |
Get the IP address. | |
Sint32 | CRM64Pro::NetTCP::getClientName (string &sClientName) |
Get the client name. | |
Sint32 | CRM64Pro::NetTCP::features (Sint32 iFeatures) |
Set or get advance features. | |
Sint32 | CRM64Pro::NetTCP::connectTo (const string &sHost, Uint16 iPort, const string &sClient, Uint32 iPasswd) |
Connect to a server. | |
Sint32 | CRM64Pro::NetTCP::sendData (void *pData, Sint32 iSize, Uint8 bIsQuery=1) |
Send a data package (blocking method). | |
eNetMsg | CRM64Pro::NetTCP::receiveData (void **pData, Uint32 *iSize) |
Receive a data package (non-blocking method). | |
Sint32 | CRM64Pro::NetTCP::freeData (void *&buf) |
Free a received data package. | |
Sint32 | CRM64Pro::NetTCP::queryKillServer () |
Query to close the server (and all the connected clients). | |
Sint32 | CRM64Pro::NetTCP::queryKillClient () |
Query to kill this client. | |
Sint32 | CRM64Pro::NetTCP::queryClientsInfo () |
Query to get updated the information of all connected clients. | |
Sint32 | CRM64Pro::NetTCP::getClientsInfo (ClientInfo **cinfo) |
Get information stored locally about all connected clients. | |
Sint32 | CRM64Pro::NetTCP::setTimeOut (Sint32 iMs) |
Set the connection timeout. | |
Sint32 | CRM64Pro::NetTCP::setSimDelay (Sint32 iMs, Sint32 iMode=0) |
Simulate a connection delay. | |
Sint32 | CRM64Pro::NetTCP::createServer (Uint16 iPort, Sint32 iPasswd, Sint32 iDedicated) |
Create a server. | |
Sint32 | CRM64Pro::NetTCP::setCoreServerCallback (Sint32(*myCoreServer)(void *pData, Sint32 iSize, void *pObj), void *pObj=nullptr) |
Set a callback function into the server thread for handling data. | |
#define NETFEATURE_DISABLE_LOGIN 1 |
Used with Features() method. Disables the log into the server for new clients
enum CRM64Pro::eNetMsg |
Network messages.
Sint32 CRM64Pro::NetTCP::info | ( | Sint32 | iMode = 0 | ) |
Request NetTCP Interface information.
For displaying the information, it uses the default log.
iMode | unused for the time being. |
Sint32 CRM64Pro::NetTCP::init | ( | Uint8 | iLM | ) |
Initialize the NetTCP system.
Before using any other method as createServer() or connectTo(), NetTCP must be initialized.
iLM | dedicated network log mode. Check LM_NULL, LM_STDOUT, LM_FILE, LM_FILEAPPEND and LM_CONSOLE for further information. You can OR'ed them. By default, it is set to LM_NULL. |
Sint32 CRM64Pro::NetTCP::close | ( | ) |
Close the NetTCP system.
Sint32 CRM64Pro::NetTCP::isServer | ( | ) |
Check if the server is running.
Sint32 CRM64Pro::NetTCP::isClient | ( | ) |
Check if the client is running.
Uint32 CRM64Pro::NetTCP::getIP | ( | ) |
Get the IP address.
Sint32 CRM64Pro::NetTCP::getClientName | ( | string & | sClientName | ) |
Get the client name.
sClientName | a string containing the client name when it is connected to a server. |
Sint32 CRM64Pro::NetTCP::features | ( | Sint32 | iFeatures | ) |
Set or get advance features.
Check NETFEATURE_x defines for a list of supported features.
iFeatures | 32bits signed integer with desired flags enabled. Enabling a current enabled flag will disable it. When you want to get only current enabled flags, use -1. |
Sint32 CRM64Pro::NetTCP::connectTo | ( | const string & | sHost, |
Uint16 | iPort, | ||
const string & | sClient, | ||
Uint32 | iPasswd | ||
) |
Connect to a server.
This method will try to connect to the server during the timeout (set by SetTimeOut()) before to return with an error. With ESCAPE key it halts the attempt.
sHost | host name or IP of the server to connect to. |
iPort | the listening server port (1024 to 65536). |
sClient | client name, must be unique and with a maximum of 16 characters. |
iPasswd | password to connect to the server. |
Sint32 CRM64Pro::NetTCP::sendData | ( | void * | pData, |
Sint32 | iSize, | ||
Uint8 | bIsQuery = 1 |
||
) |
Send a data package (blocking method).
This method will send the data package to the server and depending on the server mode, these are the different behaviour:
pData | pointer to your data. |
iSize | size in bytes of your data. |
bIsQuery | only has mean on Authoritative server mode. By default is to 1 allowing the CoreServer callback function to evaluate the data package. Any other value will bypass this evaluation. |
eNetMsg CRM64Pro::NetTCP::receiveData | ( | void ** | pData, |
Uint32 * | iSize | ||
) |
Receive a data package (non-blocking method).
The data packages may be generated by the server or by other clients.
Incoming data packages are stored on an internal queue so you can fetch all data elements calling this function until you get a return value of 0.
pData | pointer to received data package. |
iSize | pointer to integer with the size of received data (if any). |
Sint32 CRM64Pro::NetTCP::freeData | ( | void *& | pData | ) |
Free a received data package.
Do no try to use any other free function for removing this data and use this method for it.
pData | pointer to the received data. |
Sint32 CRM64Pro::NetTCP::queryKillServer | ( | ) |
Query to close the server (and all the connected clients).
Sint32 CRM64Pro::NetTCP::queryKillClient | ( | ) |
Query to kill this client.
Sint32 CRM64Pro::NetTCP::queryClientsInfo | ( | ) |
Query to get updated the information of all connected clients.
Sint32 CRM64Pro::NetTCP::getClientsInfo | ( | ClientInfo ** | cinfo | ) |
Get information stored locally about all connected clients.
When a new client is connected or disconnected, the table containing the info is automatically updated.
In case you want to know the real latency on a client, you have to call to queryClientsInfo() before to call this method.
However, if the client is running together with the server, a call to queryClientsInfo() is not needed.
cinfo | a pointer to the information. See sClientInfo struct to further information. |
Sint32 CRM64Pro::NetTCP::setTimeOut | ( | Sint32 | iMs | ) |
Set the connection timeout.
iMs | desired timeout in milliseconds used when connectTo() is used for connecting to a server. Minimum is 500ms. By default, the timeout is set to 2000ms. |
Sint32 CRM64Pro::NetTCP::setSimDelay | ( | Sint32 | iMs, |
Sint32 | iMode = 0 |
||
) |
Simulate a connection delay.
It only works for clients and could be changed at any time.
iMs | simulated connection delay in milliseconds with this range [0,2500]. By default it's set to 0. |
iMode | Reserved for future usages. |
Sint32 CRM64Pro::NetTCP::createServer | ( | Uint16 | iPort, |
Sint32 | iPasswd, | ||
Sint32 | iDedicated | ||
) |
Create a server.
iPort | the listening server port (1024 to 65536). |
iPasswd | integer with the server password. |
iDedicated | 1 for running in stand-alone mode (the call to this method will not return till the server is closed). 0 for running the server on a separated thread (the call to this method will return). |
Sint32 CRM64Pro::NetTCP::setCoreServerCallback | ( | Sint32(*)(void *pData, Sint32 iSize, void *pObj) | myCoreServer, |
void * | pObj = nullptr |
||
) |
Set a callback function into the server thread for handling data.
myCoreServer | your callback function which takes a pointer to the data and its size. An optional pObj pointer to the data/function/static method fixed when calling this method. When a callback function is used, the server run on authoritative mode, otherwise, it will run on non-authoritative mode. Using nullptr will disable any callback function. The callback function run on the server thread. It must return 0 when sent data is accepted or a negative error code when it is denied. |
pObj | pointer to data/function/static method. By default, it is not used and set to nullptr. |