In my project I have two prefabs - NetClient and NetServer.
NetServer
[AddComponentMenu( "Networking/NetServer" )]
public class NetServer : NetworkDiscovery
{
void Start()
{
Application.runInBackground = true;
StartServer();
}
//Call to create a server
public void StartServer()
{
int serverPort = CreateServer();
if( serverPort != -1 )
{
Debug.Log( "Server created on port : " + serverPort );
broadcastData = serverPort.ToString();
Initialize();
StartAsServer();
}
else
{
Debug.Log( "Failed to create Server" );
}
}
int minPort = 10000;
int maxPort = 10010;
int defaultPort = 10000;
//Creates a server then returns the port the server is created with. Returns -1 if server is not created
private int CreateServer()
{
int serverPort = -1;
//Connect to default port
bool serverCreated = NetworkServer.Listen( defaultPort );
if( serverCreated )
{
serverPort = defaultPort;
Debug.Log( "Server Created with deafault port" );
}
else
{
Debug.Log( "Failed to create with the default port" );
//Try to create server with other port from min to max except the default port which we trid already
for( int tempPort = minPort; tempPort <= maxPort; tempPort++ )
{
//Skip the default port since we have already tried it
if( tempPort != defaultPort )
{
//Exit loop if successfully create a server
if( NetworkServer.Listen( tempPort ) )
{
serverPort = tempPort;
break;
}
//If this is the max port and server is not still created, show, failed to create server error
if( tempPort == maxPort )
{
Debug.LogError( "Failed to create server" );
}
}
}
}
return serverPort;
}
}
NetClient
[AddComponentMenu("Networking/NetClient")]
public class NetClient : NetworkDiscovery
{
void Start()
{
StartClient();
}
public void StartClient()
{
Initialize();
StartAsClient();
}
public override void OnReceivedBroadcast( string fromAddress, string data )
{
Debug.Log( "Server Found: " + fromAddress + "\n" + "Data: " + data );
}
}
I have a simple UI that allows the user to select whether they are the server or client, which then adds the correct prefab to the scene.
Running both on a machine works, but when running on two or more machines, the client never receives any broadcasts. Wireshark does show that the client machine receives packets.
I tried running the Broadcast example project and the client also did not receive broadcasts. I’m running unity 2017.1.0f3.
The computers are connected using ethernet cables and a Netgear router, all running Windows 10.
Is this a known problem?