Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

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

Hello!

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 <f044fe2c9e7e4b8e91984b41f0cf0b04>:0)

System.Net.WebSockets.ClientWebSocket+<ReceiveAsync>c__AnonStorey5.<>m__0 () (at <f044fe2c9e7e4b8e91984b41f0cf0b04>: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. Any help is appreciated!

/Erik

2 Replies
gamaescalante
Contributor III
Contributor III

Did you ever get this resolved?  

gamaescalante
Contributor III
Contributor III

Did you ever get this resolved?