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

Clients stop recieving data after a little while

Discussion in 'Unity Transport' started by Pk_c, Aug 25, 2023.

  1. Pk_c

    Pk_c

    Joined:
    Jun 30, 2013
    Posts:
    11
    Hello

    I'm currently trying to implement a multiplayer solution that works with Unity Transport and MessagePack ( for serialization).

    Today I noticed that after a few seconds the client seems to stop receiving data, I tried to increase the rate at which I'm sending package from the server (I went from 1 every 100ms to 1 every 200 ms), and I noticed that it works for much longer but doesn't seem to fix the issue.

    I looked at the data volume I was sending after serialization, my byte array length is around 250 so it doesn't seem excessive to me.
    I'm testing locally only so I use the default pipeline and this endpoint to connect my client:

    Code (CSharp):
    1.             _driver = NetworkDriver.Create(settings);
    2.             var endpoint = NetworkEndPoint.LoopbackIpv4.WithPort(7777);
    3.             _hostConnection = _driver.Connect(endpoint);
    I'm really not sure what I'm doing wrong here.

    Thanks
     
  2. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    345
    What settings are you using to create the
    NetworkDriver
    ?

    When you stop receiving data, do you receive a
    Disconnect
    event on either end of the connection?

    Are the
    BeginSend
    or
    EndSend
    calls returning any error code (negative value)?
     
  3. Pk_c

    Pk_c

    Joined:
    Jun 30, 2013
    Posts:
    11
    Hello thanks for your reply

    I finally found the problem this morning, there was actually a leak on my data package, so the data sent was becoming increasingly larger after a while

    I guess when it becomes too large, it just becomes unable to receive
     
  4. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    345
    Good to read that you've solved your problem! If the data is too large you can probably also be notified of the error directly when sending. The call to
    EndSend
    should return an error if too much data was written to the
    DataStreamWriter
    .
     
  5. Pk_c

    Pk_c

    Joined:
    Jun 30, 2013
    Posts:
    11
    Hum then it makes me wonder, i do use BeginSend and EndSend, but I didn't get any error, it was just like the client stopped receiving any data suddenly.
    I also checked what you mentioned earlier, I did not get disconnected, for my setting I just left default for server and increased timeout for client ( but didn't change anything )
     
  6. simon-lemay-unity

    simon-lemay-unity

    Unity Technologies

    Joined:
    Jul 19, 2021
    Posts:
    345
    When you mention using
    BeginSend
    and
    EndSend
    , do you manually check the values they return? That's really the only way to get notified of the errors. These methods do not throw exceptions for these kinds of runtime errors, and they usually don't log either. Also, if you write too much to a
    DataStreamWriter
    , its
    HasFailedWrites
    property should be true.
     
  7. Pk_c

    Pk_c

    Joined:
    Jun 30, 2013
    Posts:
    11
    Thanks for your advices, I will try to implement some safety check