Search Unity

SSL/TLS packet losses

Discussion in 'Connected Games' started by battleofgeniuses, Sep 13, 2019.

  1. battleofgeniuses

    battleofgeniuses

    Joined:
    Jul 22, 2017
    Posts:
    1
    Hi!
    We are struggling with ssl-connection problem.

    Code (CSharp):
    1.  
    2. if (Connected)
    3. {
    4.         byte[] buffer = new byte[_client.ReceiveBufferSize];
    5.         int bytes = -1;
    6.         try
    7.         {
    8.               while (true)
    9.               {
    10.                    Log("Try read");
    11.                    bytes = _stream.Read(buffer, 0, buffer.Length);
    12.                    Log("Read: " + bytes);
    13.                    if (bytes == 0)
    14.                    {
    15.                         throw new Exception("Connection gracefully closed");
    16.                    }
    17.                    else
    18.                    {
    19.                          //parse message
    20.                    }
    21.              }
    22.       }
    23. }
    24.  
    After successful authentication and normal working for 5-30 minutes we have random packet losses.
    I understand that packet losses are normal and it's our responsibility to reconnect, but interesting that when I use Wireshark I can see that packets keep incoming and outcoming, but income-packets are not received in C#((

    Debug Logs:
    19:15:45.770: TCPSocket: Income: {"pong":[22],"payload":1568391345756}
    19:15:45.770: TCPSocket: Try read
    19:15:46.627: TCPSocket: Read: 14
    19:15:46.627: TCPSocket: Try read
    19:15:46.628: TCPSocket: Read: 1
    19:15:46.628: TCPSocket: Income: {"ping":[-11]}
    19:15:46.629: TCPSocket: Lock on queue before add
    19:15:46.629: TCPSocket: Enqueue: {"pong":[-11]}
    19:15:46.629: TCPSocket: Try read
    19:15:46.643: TCPSocket: Left in queue: 0
    19:15:46.643: TCPSocket: Outcome: {"pong":[-11]}
    19:15:46.644: TCPSocket: Written
    19:15:48.700: TCPSocket: Lock on queue before add
    19:15:48.701: TCPSocket: Enqueue: {"ping":[24]}
    19:15:48.737: TCPSocket: Left in queue: 0
    19:15:48.737: TCPSocket: Outcome: {"ping":[24]}
    19:15:48.738: TCPSocket: Written
    19:15:51.706: TCPSocket: Lock on queue before add
    19:15:51.708: TCPSocket: Enqueue: {"ping":[25]}
    19:15:51.749: TCPSocket: Left in queue: 0
    19:15:51.750: TCPSocket: Outcome: {"ping":[25]}
    19:15:51.751: TCPSocket: Written
    19:15:54.713: TCPSocket: Lock on queue before add
    19:15:54.713: TCPSocket: Enqueue: {"ping":[26]}
    19:15:54.763: TCPSocket: Left in queue: 0
    19:15:54.764: TCPSocket: Outcome: {"ping":[26]}


    Wireshark Output:

    upload_2019-9-13_19-46-16.png

    length: 142 = ping
    length: 232 = pong

    So, in Wireshark we see that for every ping we receive pong, but in c# we don't get them

    Any suggestions? Thanks in advance)