I haven"t used websocket much before. This time the supplier decided to use this. Here is the client. I checked some information. It seems that there are two ways for websocket to disconnect. One is that the client sends a request to the server, and the server responds to shut down.
var ws=new WebSocket("ws://127.0.0.1:8000");
ws.onopen=function(){
ws.close();
};
ws.onclose=function(e){
console.log(e);
};
or the server follows certain logic, such as sending close, client when data is returned, the client closes in onclose,
var ws=new WebSocket("ws://127.0.0.1:8000");
ws.onclose=function(e){
console.log(e);
ws.close(); //TCP
};
does not take the initiative to close at first, that is, it does not use ws.close () to close it, although it seems to close automatically, but it seems that one is not disconnected, and then sending the second will be a problem. If I don"t know whether the server will shut down actively, will there be a problem if I write ws.close () in both onopen and onclose?