Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the demo "on_close" is not valid #19

Open
iamzhuang opened this issue Mar 18, 2022 · 0 comments
Open

the demo "on_close" is not valid #19

iamzhuang opened this issue Mar 18, 2022 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@iamzhuang
Copy link

iamzhuang commented Mar 18, 2022

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!

@iamzhuang iamzhuang added the bug Something isn't working label Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants