A simple networking solution for client-server communication
Great for simple games and apps where you dont want to touch the network and just want to send some data and not care about how it gets there
Preatty performant and low overhead in most cases
All you need to include for the package to work is the package itself
using NetWolt;
To setup the server all you need to do is to create an instance of the server class and it will automatically start the server on the provided port
Server server = new Server(<port>);
The setup is almost the same for the client, but this time you need to include an address as well. The client will then start connecting to the server
Client client = new Client(<address>, <port>);
The basic data unit for sending and receiving data with the package is called a command
A command is just a collection of basic data types
To create a command simply instantiate it and fill it with parameters
Command cmd = new Command();
cmd.addParameter(<data>);
cmd.setParameter(<possition>, <data>);
To read parameters from a command simply use the getParameter method
Command cmd = new Command();
cmd.addParameter(<data>);
int data = (int)cmd.getParameter(0);
The functions for sending commands differ from client to server slightly
For the client you can just use the sendCommand method as shown bellow
Command cmd = new Command();
cmd.addParameter(<data>);
client.sendCommand(cmd);
For the server you need to specify the client you want to send the command to with a clientId integer
Command cmd = new Command();
cmd.addParameter(<data>);
server.sendCommand(<clientId>,cmd);
Or you can send the command to all connected clients
Command cmd = new Command();
cmd.addParameter(<data>);
server.sendCommandToAll(cmd);
To read received commands from the server or client you need to use the nextCommand method
As with the previous method the method is a bit different for the server and the client. The server needs the clientId as an argument.
we can first make sure there are any new commands by using the newCommands method and then poll for received commands with the nextCommand method
if (server.newCommands(<clientId>))
{
Command cmd = server.nextCommand(<clientId>);
}
if (client.newCommands())
{
Command cmd = client.nextCommand();
}