Search Unity

Losing connection to Qlik Sense app after 3 minutes

Discussion in 'Editor & General Support' started by unity_k8l-aLPYNdoZrQ, Jan 9, 2018.

  1. unity_k8l-aLPYNdoZrQ

    unity_k8l-aLPYNdoZrQ

    Joined:
    Dec 6, 2017
    Posts:
    3
    Hello All,

    I currently have a connection to qlik that is based on websockets and JSON, that is run through a C# script in the Unity engine. It works perfectly fine to begin with, but after roughly 3 minutes, the connection is lost and I get an ObjectDisposedException which makes me unable to recieve Qlik messages.

    Code (CSharp):
    1. ObjectDisposedException: Cannot access a disposed object. Object name: 'System.Net.Sockets.NetworkStream'. System.Net.WebConnection.Read (System.Net.HttpWebRequest request, System.Byte[] buffer, System.Int32 offset, System.Int32 size) (at :0) System.Net.WebSockets.ClientWebSocket+c__AnonStorey5.<>m__0 () (at :0)
    My method for recieving messages form QlikView:

    Code (CSharp):
    1. private static async void ReceiveWs(ClientWebSocket ws)
    2.     {
    3.         // Keep listening while socket is open
    4.         while (ws.State == WebSocketState.Open)
    5.         {
    6.             // Receive in chunks through byte array
    7.             WebSocketReceiveResult incoming;
    8.             String resultString = "";
    9.             do
    10.             {
    11.                 Byte[] bufferByte = new byte[1024];
    12.                 incoming = await ws.ReceiveAsync(new ArraySegment<byte>(bufferByte), CancellationToken.None);
    13.                 resultString += Encoding.UTF8.GetString(bufferByte).TrimEnd('\0');
    14.             }
    15.             while (!incoming.EndOfMessage);
    16.  
    17.              ...
    18.  
    19.         }
    20.     }
    I think the problem originates in this code, but I am not quite sure. I can provide more code if you think it is needed. Any help is appreciated!

    Regards
    Sarahjohn