in Samples~/SampleGame/Assets/Scripts/Server/NetworkServer.cs [24:68]
public void Update()
{
// Are there any new connections pending?
if (_listener.Pending())
{
TcpClient client = _listener.AcceptTcpClient();
for (int x = 0; x < 4; x++)
{
if (_clients[x] == null)
{
_clients[x] = client;
UpdateNumConnected();
_gl.Log.WriteLine("Connection accepted: playerIdx " + x + " joined");
return;
}
}
// game already full, reject the connection
_gl.Log.WriteLine("Connection rejected: game already full.");
try
{
NetworkProtocol.Send(client, "REJECTED: game already full");
}
catch (SocketException) { }
}
// Have we received an input event message from any client?
for (int x = 0; x < 4; x++)
{
if (_clients[x] == null)
{
continue;
}
string[] messages = NetworkProtocol.Receive(_clients[x]);
foreach (string msgStr in messages)
{
_gl.Log.WriteLine("Msg rcvd from playerIdx " + x + " Msg: " + msgStr);
HandleMessage(x, msgStr);
}
}
}