- Home /
How to close websocket connection on server?
I have a multiplayer game using Unity 5.6 with a WebGL client and a linux server, using websocket connections. It seems that calling NetworkConnection.Disconnect() on the server does not disconnect until it gets a response from the client. However in the case where the client has stopped responding, no response is received so the connection is not closed. Is this the proper way to close the connection?
To reproduce:
-Call NetworkConnection.Disconnect() on server with a functional client, and the connection is successfully disconnected and the player controller destroyed.
-Pause script execution in the Javascript console of the client, then call NetworkConnection.Disconnect(). The NetworkConnection is never disconnected and the player's gameobject remains on the server.
I've been able to partially solve this issue using Unity 2017.2.0f3. I still don't know how to properly close the connection but to remove the player's gameobject on the server, I call NetworkServer.DestroyPlayersForConnection(conn); where conn is a type of NetworkConnection.
After a few test it seems you have to do NetworkConnection.Disconnect() followed by NetworkConnection.Dispose() to fully close the connection but I'm not entirely sure that the connection is fully closed.
Answer by bliu886 · Jan 25, 2018 at 01:42 PM
To fully close the connection, you have to have NetworkConnection.Disconnect() followed by NetworkConnection.Dispose(); To remove the player's gameobject on the server call NetworkServer.DestroyPlayersForConnection(conn) where conn is a type of NetworkConnection.
Your answer
![](https://koobas.hobune.stream/wayback/20220612151218im_/https://answers.unity.com/themes/thub/images/avi.jpg)