when with portfowarding the websocket pass by internet and only send when the connexion is close (on my network it's like that), I first try to close the websocket by closing chrome(it worked), so now i found terminate that i think can do the same than closing the webbrowser,but it's only for the serveur that have this function and
the problem is that the buffer with close is not 0 but 13...
so how can i do a hard close with ws.terminate or something else to flush the buffer to 0 and a basic code like the one under without having the error?
ws = new WebSocket("ws://adress:5677/"),
messages = document.createElement('ul');
ws.onopen = function (event) {
alert("connect");
var lol = document.getElementById('lolz').value;
alert(lol);
ws.send(lol+" <p>\b\n\r");
ws.close();
console.log(ws.readyState);
if(ws.readyState ==2){
alert("ws.terminate");
return ws.terminate();
}
}
if you look the picture and the code you can see that i usews.close but it doesn't seems to do something the buffer is not to zero and it's still connected this is a pictures of what is the status of the Websocket after ws.close(), i think that ws.close() waits that the serveur also close the connection and when the serveur waits to receive something before closing the serveur, it put's an error.
my pthon serveur if never
async def Time(websocket, path):
try:
a=await websocket.recv()
print("final receive:"+str(a)+"/")
a=str(a).split("<p>")
a=a[0]
print("/"+str(a)+"/")
except:
print("erreur")
finally:
socketout(bytes(a.encode("utf-8")))
print("loop stop")
loop.stop()
print("loop ad stop")
start_server = websockets.serve(Time, "", 5678)
loop3=asyncio.get_event_loop()
loop3.run_until_complete(start_server)
a visual explication Thanks for helping [![visual][2]][2]

