NetworkEvent.Type.Connect is not being sent

Hi all, I’ve been trying to get Transport working with my custom TCP server for some time now and decided to stop bashing my head and ask for help.

I’ve followed what I could find on the internet regarding Transport which is not much but allowed me to hack together something that should be working, I guess… My first problem starts with the TCPNetworkInterface being internal, which I fixed by forking the project from needle-mirror which seems to be a pretty up-to-date unnoficial fork and got the client to connect to the server.

9450206--1326590--upload_2023-11-4_16-43-41.png

Then a new problem shows up: neither Driver.PopEventForConnection nor Connection[0].PopEvent seems to be receiving the NetworkEvent.Type.Connect. While investigating and pulling the wire I can see ConnectionList.FinishConnectingFromLocal is called, but regardless of the m_FinishedConnections.Enqueue(connectionId); being called, TopLayer’s CompleteReceiveJob doesn’t seem to see that ConnectionId which was just enqueued.

I’ve spread a bunch of logs through ConnectionList and this is what I see:

9450206--1326596--upload_2023-11-4_16-49-34.png

My code can be found at this gist (in order to keep this thread readable).

Is anything wrong with the TCPNetworkInterface hence it’s still internal or is there something wrong with my code either client or server side? Thank you

Unity Transport implements its own protocol on top of UDP (or TCP in this case) which is what drives the connection events. That is, no connection event will be generated until the handshake of the custom protocol has been completed. In this case your custom TCP server probably does not implement that protocol, hence why no connection events are generated.

It looks like you’re trying to use Unity Transport as a general-purpose TCP client, but that’s not what the library is meant to be. Communications with servers that are not themselves running Unity Transport is not supported. To create a general-purpose TCP client, using .NET sockets would be the recommended approach.

Oh yes, that’s exactly what I was trying to do, since the general proposal of the solution seemed very robust and being able to use the Job System gave it some points. There isn’t many people talking about solutions as elegant as Transport on the internet… I guess I’ll have to put together some solution using a TCP client then, thank you!