Search Unity

[LLAPI] Offloading sending/receiving to a thread

Discussion in 'Multiplayer' started by tomasara413, Aug 1, 2018.

  1. tomasara413

    tomasara413

    Joined:
    Feb 25, 2017
    Posts:
    3
    Hello there community. The questions are simple - is it possible to somehow offload the NetworkTransport.Send/Receive to another thread and if it is, how.
    You see, processing network requests from the main thread is simply not a good idea. On the main thread you my process only limited amount of messages because you have to update the frame and the other mechanics. Essentially with a high update rate, it will slowly make the buffer/queue bigger and bigger and requests not processed.
    Thank you for answers.

    EDIT: Since the UNet has been announced deprecated, answering this question is essentially meaningless, the game is in an early development and by the time we finish we would have to migrate.
     
    Last edited: Aug 5, 2018
  2. Njb_

    Njb_

    Joined:
    Jun 3, 2015
    Posts:
    20
    unity jobs system maybe?
     
  3. tomasara413

    tomasara413

    Joined:
    Feb 25, 2017
    Posts:
    3
    Job system not fit for this since it is designed as a thread pool and the jobs should be running only for a short amounts of time. What I am thinking here would be a long running thread.
     
  4. aabramychev

    aabramychev

    Unity Technologies

    Joined:
    Jul 17, 2012
    Posts:
    574
    consider my answer as deprecated :) : there are two callbacks which you can setup. one for reading (there is something for read) another for writing. Receiving callback signal you can start read task as generic .net async operation....
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  6. KevinHGS

    KevinHGS

    Joined:
    May 29, 2017
    Posts:
    11
    In currently, the Receive & Send function must be invoked at main thread.