Client and Server - TextGuySemicolon/VPPMultiplayer GitHub Wiki
"GameServer" and "GameClient" is the main "NetManager" script that handle every network operation for client/server.
Both "GameServer" and "GameClient" construct the important LiteNetLib feature in static field, we will then implement network logic by create external script to interact with these static references.
public static NetManager netManager;
public static EventBasedNetListener netEventListener;
public static NetPacketProcessor netPacketProcessor;
Networking Logic
When it comes to writing networking logic for server/client, we separate the networking components into 2 script, one is interacting with "GameServer", one is interacting with "GameClient", for example "NetworkLogic" is a network feature you want to implement. We will separate it into "ClientNetworkLogic" and "ServerNetworkLogic".
Callback
The main method we used to interact with network, is by using callback for "NetPacketProcessor" and/or "EventBasedNetListener". for more information
NetPacketProcessor Callback
We will subscribe callback functions to the static "NetPacketProcessor" from "GameServer" or "GameClient".
for server:
GameServer.netPacketProcessor.SubscribeReusable<SamplePacket>(OnSamplePacketReceived);
for client:
GameClient.netPacketProcessor.SubscribeReusable<SamplePacket>(OnSamplePacketReceived);
Network Event Callback
same workflow when we want to subscribe network event callback, we use the static "EventBasedNetListener" from "GameServer" or "GameClient".
for server:
GameServer.netEventListener.PeerDisconnectedEvent += OnPeerDisconnected;
for client:
GameClient.netEventListener.PeerDisconnectedEvent += OnPeerDisconnected;