the demo "on_close" is not valid
hello, I used the code and add print message on_close.
=====================================================
from wsocket import WSocketApp, WebSocketError, logger, run
from time import sleep
logger.setLevel(10) # for debugging
def on_close(self, message, client):
print("come to the on_close_____________")
print(repr(client) + " : " + message)
def on_connect(client):
print(repr(client) + " connected")
def on_message(message, client):
print(repr(clent) + " : " + repr(message))
try:
client.send("you said: " + message)
sleep(2)
client.send("you said: " + message)
except WebSocketError:
pass
app = WSocketApp()
app.onconnect += on_connect
app.onmessage += on_message
app.onclose += on_close
run(app)
===================================================
$ python3 hello_world.py
Server started at http://127.0.0.1:8080.
DEBUG:wsocket:Protocols allowed:
DEBUG:wsocket:WebSocket request accepted, switching protocols
<wsocket.WebSocket object at 0x7fc744c01100> connected
opcode close
close called
DEBUG:wsocket:Closed WebSocket
receive closed
Connection is already closed
127.0.0.1 - - [19/Mar/2022 00:05:22] "GET / HTTP/1.1" 101 4
close called
receive closed
Connection is already closed
receive closed
Connection is already closed
DEBUG:wsocket:Failed to write closing frame -> closing socket
DEBUG:wsocket:Closed WebSocket
the message above is I run the hello_world.py.
when I closed the websocket connect by the client. It did not go the the " on_close(self, message, client):" ,and not print the message :"come to the on_close_____________"
Some one can try to check the code and tell me why not message is printed on_close?
Thank you!
the demo "on_close" is not valid
hello, I used the code and add print message on_close.
=====================================================
===================================================
$ python3 hello_world.py
Server started at http://127.0.0.1:8080.
DEBUG:wsocket:Protocols allowed:
DEBUG:wsocket:WebSocket request accepted, switching protocols
<wsocket.WebSocket object at 0x7fc744c01100> connected
opcode close
close called
DEBUG:wsocket:Closed WebSocket
receive closed
Connection is already closed
127.0.0.1 - - [19/Mar/2022 00:05:22] "GET / HTTP/1.1" 101 4
close called
receive closed
Connection is already closed
receive closed
Connection is already closed
DEBUG:wsocket:Failed to write closing frame -> closing socket
DEBUG:wsocket:Closed WebSocket
the message above is I run the hello_world.py.
when I closed the websocket connect by the client. It did not go the the " on_close(self, message, client):" ,and not print the message :"come to the on_close_____________"
Some one can try to check the code and tell me why not message is printed on_close?
Thank you!