ClientConnection
public class ClientConnection : GameConnection
{
public int serverPort;
public string serverIP;
public int numberOfPlayerInputsToSend = 5;
private NetPeer serverPeer;
public bool connected = false;
EventBasedNatPunchListener natPunchListener = new EventBasedNatPunchListener();
//...
This class helps connect a client to a server and extends the GameConnection class. It keeps the serverPort and serverIP handy as attributes. It has an attribute NetPeer serverPeer which is used so the client can send messages to the server at will. Also has a natPunchListener to help aid in getting around port forwarding nonsense.
Methods
public ClientConnection(int port, int serverPort, string serverIP)
A constructor that takes a port to start listening on and also the server port and IP.
private void SetupListenerEvents()
Sets up a bunch of network listener events such as ReceiveNetworkEvent, PeerDisconnectEvent and a couple of others
public ClientConnection(int port, IPEndPoint serverEndPoint)
Another constructor taking a port to listen on and an IPEndPoint which houses the IP and port of the server it will attempt to connect to
public ClientConnection(int port)
Basic constructor that takes a port to start listening on
public void Connect( IPEndPoint serverEndPoint)
Attempts to make a connection to a servers IPEndPoint(IP and port) which is also stores against serverIP and serverPort attributes
public override void Update()
Poll for any incoming network events e.g receiving a packet of data. Also sends any inputs we have actioned locally off to the server too
public void NatPunchJoinGame(int gameID, IPEndPoint masterserverIP)
Let Master Server know which game server we would like to join and initiate NAT hole punch procedure
public void SendPlayerInputs()
If the player has any new user inputs from a keyboard, mouse or gamepad they have actioned on their end, then this method will send it to the server