Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved NetworkEvent.Type.Connect is not being sent

Discussion in 'Unity Transport' started by Danil0v3s, Nov 4, 2023.

  1. Danil0v3s

    Danil0v3s

    Joined:
    Sep 22, 2014
    Posts:
    45
    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.

    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.

    upload_2023-11-4_16-48-45.png

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

    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
     
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    441
    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.
     
  3. Danil0v3s

    Danil0v3s

    Joined:
    Sep 22, 2014
    Posts:
    45
    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!