heroku-python / flask-sockets

[DEPRECATED] Alternative: https://github.com/miguelgrinberg/flask-sock
MIT License
1.74k stars 164 forks source link

Question: how to make ws socket receive non-blocking ? #30

Closed StudentForever closed 8 years ago

StudentForever commented 8 years ago

Hi

I am a python newbie, I am wondering what are good options for making the socket receive method non-blocking on the serve-side ?

Thanks

kennethreitz commented 8 years ago

This project uses gevent, so all blocking calls are automatically added to an event loop, and behave asynchronously.

kennethreitz commented 8 years ago

p.s. @StudentForever, your username is fantastic. :)

StudentForever commented 8 years ago

Hi

I attached the python server and Js client code.

I have added my questions as inline comments in the code but here they are

  1. ws.receive() seems to be blocking until it receives message from websocket client from the JS code
  2. when I close the socket from JavaScript client, I don't think the connection is getting closed. I might be doing something dumb but cannot figure it out yet.

Tried this from chrome (Version 49.0.2623.112 m) and IE (version: 11.0.9600.18163).

On IE, after I tried closing the socket from JS Client, I got an error: SCRIPT12002: WebSocket Error: Network Error 12002, The operation timed out

Thanks a lot for your time.

example.zip