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.

Unity Multiplayer [LLAPI] When to call NetworkTransport.Recieve()?

Discussion in 'Multiplayer' started by zotey, Apr 6, 2016.

  1. zotey

    zotey

    Joined:
    Nov 14, 2012
    Posts:
    26
    Hey all,

    My quick question is: When to call NetworkTransport.Recieve()?
    Should I do this in the Update method or since I don't have one, in a loop?

    Both solutions seems so wrong to me.

    Thanks for any help,

    Zotey
     
  2. Ahndrakhul

    Ahndrakhul

    Joined:
    Mar 7, 2015
    Posts:
    23
    In all of the examples I've seen, it gets called in Update(). The transport layer API manual shows it like this:

    Code (CSharp):
    1. void Update()
    2. {
    3.     int recHostId;
    4.     int connectionId;
    5.     int channelId;
    6.     byte[] recBuffer = new byte[1024];
    7.     int bufferSize = 1024;
    8.     int dataSize;
    9.     byte error;
    10.     NetworkEventType recData = NetworkTransport.Receive(out recHostId, out connectionId, out channelId, recBuffer, bufferSize, out dataSize, out error);
    11.     switch (recData)
    12.     {
    13.         case NetworkEventType.Nothing:         //1
    14.             break;
    15.         case NetworkEventType.ConnectEvent:    //2
    16.             break;
    17.         case NetworkEventType.DataEvent:       //3
    18.             break;
    19.         case NetworkEventType.DisconnectEvent: //4
    20.             break;
    21.     }
    22. }