Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Send a packet of unlimited length, in a NetCode connection.

Discussion in 'NetCode for ECS' started by NovaEiz, Jun 7, 2021.

  1. NovaEiz

    NovaEiz

    Joined:
    Sep 6, 2017
    Posts:
    53
    How do I send a string in a NetCode connection?
    That is, how to send a regular packet through a connection that works with ECS components?
     
  2. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    There is no easy way to send a custom packet through the same connection we use for snapshots and rpcs.

    Unlimited length strings is not something we are optimizing for, but if you just need to send long string I think the easiest would be to send it through rpcs. You could create an rpc which has a FixedStringX + curFragment + numFragments, that way you can fragment the string into multiple rpcs and reconstruct them on the other end.

    Can you describe your use-case so we can make sure we are considering it for our future plans?
     
  3. skiplist

    skiplist

    Joined:
    Nov 9, 2014
    Posts:
    45
    Hey, just chiming in since I did this recently.

    My use case was to have some player save data being sent serialized to server at start to initialize some values. While we can add the values needed to the RPC explicitly, it is just so much more convenient to have all data in the same form both on client and server. The client has a lot of Monobehaviour stuff still so we are not a "pure" DOTS project by any means.

    I ended up making my own "FixedBytes" struct with uints of a size that would be reasonable to always fit the data and adding that to the RPC and bumping the allowed size of RPCs.

    Some observations I made:

    - You hit the 1 MTU limit really quickly when sending this kind of data as RPC. The fragmentation scheme you mentioned is a neat trick, just a bit inconvenient. I get that you typically want to send a single packet, but is there really much of a downside to use a fragmented pipeline here to allow for sending larger packets?

    - Having a struct of uints means that serialization (WritePackedUint) is done per uint instead of per byte (like with FixedString). I assume this is better, but not sure how much it matters with the compression?
     
  4. NovaEiz

    NovaEiz

    Joined:
    Sep 6, 2017
    Posts:
    53
    Я
    I want to send JSON data for game items whose characteristics can be added by players.
     
  5. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    There are a lot of problems with fragmentation together with reliable using a limited window size. I'm not sure that is robust enough to just work right now, but I expect it will be at some point in the future and when it is I expect that we will use it.
     
  6. skiplist

    skiplist

    Joined:
    Nov 9, 2014
    Posts:
    45
    Is this mainly because of the amount of packets sent or something more specific to fragmentation? Like if I send single packets through fragmentation and reliable is that somehow worse than just reliable?
     
  7. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    Sending one fragmented message will use multiple slots in the reliable send window, it could even be that it in fact needs more slots than the send window. The fragmentaion pipeline uses send resume calls to deliver all the fragments - and I don't think it deals with send failures during resume the correct way - which could lead to packets not being possible to send, or even being silently dropped. If you send a small message which only requires a single fragment that will not happen.
     
    skiplist likes this.