Trouble with NetworkTransport

I’m trying to use NetworkTransport to establish a connection between two separate machines. But any connection attempt from the client to the server is not seen by the server. I tried different socketPorts, but nothing works and I’m stumped. Can anyone see what is wrong?

On both client and server I run this to initialize:

private void initNetwork() {
    NetworkTransport.Init();
    ConnectionConfig config = new ConnectionConfig();
    c1 = config.AddChannel(QosType.Reliable);
    topology = new HostTopology(config, 10);
    hostId = NetworkTransport.AddHost(topology, socketPort);
}

Then, on the client, I run this to request a connection. I get no errors (NetworkError.OK )

connectionId = NetworkTransport.Connect(hostId, serverIp, socketPort, 0, out err);

The server is listening for incoming calls like this (called from Update) but it never gets anything other than NetworkEventType.Nothing

private void handleServer() {
    int recHostId;
    int connectionId;
    int channelId;
    int dataSize;
    byte error;

    byte[] workingBuffer = new byte[1024];
    byte[] recBuffer;

    NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, workingBuffer, workingBuffer.Length, out dataSize, out error);
  
    if (recData == NetworkEventType.Nothing)
        return;

    // it never gets here   
    Debug.Log("Event: " + recData.ToString());

    recBuffer = new byte[dataSize];

    if (dataSize > 0) {
        Buffer.BlockCopy(workingBuffer, 0, recBuffer, 0, dataSize);
    }

    switch (recData) {
        case NetworkEventType.ConnectEvent: Debug.Log("Connected!"); break;
        case NetworkEventType.DisconnectEvent: Debug.Log("Disconnected!"); break;
        case NetworkEventType.DataEvent: Debug.Log("Data!"); break;
    }
}

Anyone?

No errors from frame polling on either server or client?

That would mean something is preventing the socket from connecting. Software (commonly firewall. Windows firewall for example is really shit and you might have to go in and remove the block if you pressed cancel when the firewall prompted you about Unity for the first time) and NAT. Those are the most common problems.

I’m not sure what you mean by frame polling. But I don’t seem to be getting any errors from NetworkTransport.Connect
I used a packet sniffer to verify that I am getting messages from the client on the server and I do. Its just that in unity, it does not register the connect event.

Poll the Receive method every frame.

The client does not give an error on Connect and the server does not give any errors on Receive, but the NetworkEventType is always Nothing.

Alright, so I was using Receive instead of ReceiveFromHost. Now it is working. Took me a while to figure out!