Losing connection to Qlik Sense app after 3 minutes (Websockets & C#)

时间:2017-08-04 13:09:59

标签: c# .net unity3d websocket qliksense

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.

Part of the exception:

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 Qlik:

private static async void ReceiveWs(ClientWebSocket ws)
    {
        // Keep listening while socket is open
        while (ws.State == WebSocketState.Open)
        {
            // Receive in chunks through byte array
            WebSocketReceiveResult incoming;
            String resultString = "";
            do
            {
                Byte[] bufferByte = new byte[1024];
                incoming = await ws.ReceiveAsync(new ArraySegment<byte>(bufferByte), CancellationToken.None);
                resultString += Encoding.UTF8.GetString(bufferByte).TrimEnd('\0');
            }
            while (!incoming.EndOfMessage);

             ...

        }
    }

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! /Erik

0 个答案:

没有答案