[NATIVE] Server Comm
Posted: Sat Sep 26, 2026 5:06 pm
Server Comm
Version 0.0.2
Introduction:
This idea is based on 2 or more servers sending data between each other and also making it very simple for the coders involved.
With this include, you need only 3 functions to be able to have your servers communicate however you want!
Requirements:
Engine Module
Sockets HZ Module
Windows
Linux
Sending Data:
To be able to even have data come in, someone has to send it.
Here is the first function to send data:
Seems pretty straight-forward, right?
You send data to an IP address of the server you choose.
If you need to format the data for the send function, you don't have to format it into another variable and then send it.
Instead, you can use this function:
This reduces the formatting of the string to another variable and directly formats it into the send function.
Receiving Data:
To receive data from other servers, you need this forward in your plugin:
That will provide you with the data that you received and the length of it.
Unfortunately, these functions cannot automatically detect the IP that the data is being sent from.
Therefore, if you want the IP to go to the receive function, you have to send the IP in the data you are sending to the server.
Notes:
The API plugin needs to be compiled with the sockets_hz.inc file attached to the bottom of this post.
Be sure to set this cvar on servers running this plugin:
The value of this cvar is used to protect the data being sent and received between servers.
If the value of this cvar does not match the value of the cvar on the server running Server Comm, then the data will be ignored.
Version 0.0.2
Introduction:
This idea is based on 2 or more servers sending data between each other and also making it very simple for the coders involved.
With this include, you need only 3 functions to be able to have your servers communicate however you want!
Requirements:
Engine Module
Sockets HZ Module
Windows
Linux
Sending Data:
To be able to even have data come in, someone has to send it.
Here is the first function to send data:
Code: Select all
/*
* Sends data to a given IP
*
* @param ip - The IP to send data to
* @param data - The data to send
*
* @note The port must be at the end of the IP address
* @note To send data back to the same server, use "loopback" as the IP and no port at the end of it
*
* @return Returns 1 on success, 0 on failure
*
*/
native scomm_send(const ip[], const data[]);You send data to an IP address of the server you choose.
If you need to format the data for the send function, you don't have to format it into another variable and then send it.
Instead, you can use this function:
Code: Select all
/*
* Sends formatted data to a given IP
*
* @param ip - The IP to send data to
* @param format - The format of the data
*
* @note The port must be at the end of the IP address
* @note To send data back to the same server, use "loopback" as the IP and no port at the end of it
*
* @return Returns 1 on success, 0 on failure
*
*/
native scomm_sendf(const ip[], const format[], any:...);Receiving Data:
To receive data from other servers, you need this forward in your plugin:
Code: Select all
/*
* Called when the server receives data from another server
*
* @param data - The string containing data
* @param len - The length of the data
*
* @return Return value is ignored
*
*/
forward scomm_receive(data[], len);Unfortunately, these functions cannot automatically detect the IP that the data is being sent from.
Therefore, if you want the IP to go to the receive function, you have to send the IP in the data you are sending to the server.
Notes:
The API plugin needs to be compiled with the sockets_hz.inc file attached to the bottom of this post.
Be sure to set this cvar on servers running this plugin:
Code: Select all
scomm_key "key"If the value of this cvar does not match the value of the cvar on the server running Server Comm, then the data will be ignored.