Hi everyone!
I’m working on a 2D multiplayer platform shooter.
For the networking I am using Unity’s LLAPI. This is my first time working with the LLAPI so the issue is probably in my code.
I’m currently testing with up to 4 players - 3 clients, and 1 host (Client with a server manager in scene)
My setup is that each client sends their position to the server at a frequency of 30hz.
The server then records it in its own scene.
The server, regardless of client messages, sends updates to all clients (Except host) for every player object in its scene (Except for the object that belongs to the recipient). At a frequency of 30hz as well.
My issue, is that when testing this out with just two players, my bandwidth is up there at about 200Kb/s upload on the server side. This goes up to about 2Mb/s with just four players.
The position updates are three floats (Vector 3 pos) and a byte (Object’s ID) per message. So a total of 13 bytes per message. So with 4 players, considering one is a host, the bandwidth used should be (13x3x3x30=117) 3510 bytes/s or just 27.4Kb/s. (A bit more I’m sure, because the message has some more properties of its own. But still marginally less than 2Mb/s)
// For Pos Updates: Recieves the message, and the object's ID
public void SendClientUpdateAll(NetMsg msg, byte ID){
// The buffer holds the data
byte[] buffer = new byte[BYTE_SIZE];
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream ms = new MemoryStream(buffer);
formatter.Serialize(ms, msg);
// MAX_USER = 4. i = client ID. clientArray*=connectionId of a client. clientArray[0] is server.*
// <i != ID> Make sure we’re not sending a player their own position (Client authoritative)
for(int i = 1; i < MAX_USER; i++) {
if(clientArray != 0 && i != ID) {
NetworkTransport.Send(hostID, clientArray*, unreliableChannel, buffer, BYTE_SIZE, out error);
_}
}
}
This is the function that calls the actual NetworkTransport.Send(). It calls Send up to 3 times per run (Depending on number of connections). And is in turn called by another function up to 4 times (With different positions in “msg” every time)
----------*
I must be missing something obvious, but the documentation on LLAPI is scarce enough that I can’t find it. If anyone has any experience with this, any help would be greatly appreciated.
Thanks!_
Thanks for the answer. In your opinion which of the systems is the most flexible and gives the developers the most control?
– darksider2000