RTC Forums

Subscription => Support => Topic started by: Ecole7 on April 22, 2017, 07:02:39 PM



Title: Multiples RTC WebSocket connexions in one http connexion
Post by: Ecole7 on April 22, 2017, 07:02:39 PM
Hello

Concerning the program "WSockServTest" I note that if you refresh the browser page the number of Websocket connections displayed increases each time, but when you close the browser all connections are closed. This is true for all browser except for Internet explorer which closes each time the previous connection ...

My question is: how can we handle this problem to have a standard behavior for all browsers.

Greetings

Vincent Blanc


Title: Re: Multiples RTC WebSocket connexions in one http connexion
Post by: D.Tkalcec (RTC) on April 22, 2017, 08:18:38 PM
After a HTTP connection has been upgraded to a Web Socket, the TCP/IP connection previously used for HTTP communication can ONLY be used to send and receive Web Socket "Frames". Sending or receiving HTTP requests or responses through that same connection is no longer possible. In other words, a Web Browser (or any other Client) can NOT use one HTTP connection to open multiple Web Sockets.

Normally, Clients should close TCP/IP connections when they are no longer used, but nothing is stopping a Web Browser (or any other Client) from opening a new TCP/IP connection, sending a new HTTP request through that new TCP/IP connection and upgrading that new connection to a Web Socket, while at the same time leaving the old TCP/IP connection open (which also leaves the old Web Socket open - until the TCP/IP connection is closed).

Most Web Browsers will be sending a WebSocket "Frame" with the opcode "Close" when they are finished using a Web Socket. In the OnWSDataReceived event, you can check if Sender.FrameIn.wfOpcode=ws_Close, which usually means that the connection is no longer needed and can safely be closed.

You can close any RTC connection (HTTP, TCP/IP or a Web Socket) by using the "Disconnect" method, or ... you can use one of the "wsDisconnect" methods to close one or more Web Socket connections.

Best Regards,
Danijel Tkalcec


Title: Re: Multiples RTC WebSocket connexions in one http connexion
Post by: Ecole7 on April 24, 2017, 07:41:51 AM
Hello,
Thanks for the very quick and complete answer on how Websockets work.
I actually noticed that on some browsers, if you reload a page, the previous connection remains open for about ten seconds before closing.

So now everything is clear to me about this.

Greetings
Vincent Blanc