Closing WebSocket correctly (HTML5, Javascript)

后端 未结 5 1918
悲哀的现实
悲哀的现实 2020-11-28 02:13

I am playing around with HTML5 WebSockets. I was wondering, how do I close the connection gracefully? Like, what happens if user refreshes the page, or just closes the brows

5条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 02:56

    Very simple, you close it :)

    var myWebSocket = new WebSocket("ws://example.org"); 
    myWebSocket.send("Hello Web Sockets!"); 
    myWebSocket.close();
    

    Did you check also the following site And check the introduction article of Opera

提交回复
热议问题