Hi!
I’m trying to create a server client model using the NetworkTransport classes. However when attempting to connect using my client to the server I’ll get a DisconnectEvent with a TimeoutError on the server side.
Here’re some snippets from both the server and client (omitting some code):
Server
// Host setup on Start
ConnectionConfig connConfig = new ConnectionConfig();
m_ReliableChannelId = connConfig.AddChannel(QosType.ReliableSequenced);
HostTopology topology = new HostTopology(connConfig, m_MaxConnections);
m_HostId = NetworkTransport.AddHost(topology, 8888);
// Inside my Update() method
int recHostId;
int connectionId;
int channelId;
int bufferSize = 1024;
byte[] recBuffer = new byte[bufferSize];
int dataSize;
byte error;
// TODO Handle errors such as buffer too small
NetworkEventType evt = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
if (error != 0)
{
// TODO error handling!!!
Logger.Log("Server recv: " + evt + " error: " + (NetworkError)error);
}
Client
// Setup in Start()
ConnectionConfig connConfig = new ConnectionConfig();
m_ReliableChannelId = connConfig.AddChannel(QosType.ReliableSequenced);
HostTopology topology = new HostTopology(connConfig, m_MaxConnections);
m_HostId = NetworkTransport.AddHost(topology);
// Client handshake code (which fails), also IENumerable
byte error;
m_ConnectionId = NetworkTransport.Connect(m_HostId, "172.0.0.1", 8888, 0, out error);
if (error != 0)
{
Logger.Log("Error connecting to server. ErrorID: " + error);
yield break;
}
// Wait untill we've fully established a connection.
while (!m_Connected) yield return null;
// Etc. etc.
// Update() Method
int recHostId;
int connectionId;
int channelId;
int bufferSize = 1024;
byte[] recBuffer = new byte[bufferSize];
int dataSize;
byte error;
// TODO Handle errors such as buffer too small
NetworkEventType evt = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
if (error != 0)
{
// TODO error handling!!!
Logger.Log("Client recv error: " + error + " evt: " + evt);
}
The server will wait for a connection on port 8888, which the clients connects to. The client does not specify a local host port (port on which the client will accept connections) so the OS will figure out which available port to use. The client, during initialisation, will do StartCoroutine to connect to the server on port 8888. After about a few seconds on the server side NetworkTransport.Receive returns a DisconnectEvent with a NetworkError.Timeout.
Does anyone have any suggestions or an idea as to what might be wrong?