Comments (7)
Interesting. The socket.io specification clearly states that the connection needs to start as long-polling (https://github.com/socketio/engine.io-protocol#transport-upgrading), and then it is upgraded to websocket. That's the use case I have implemented, so the fact that you connect with long-polling does not mean it stays that way forever, you can confirm it upgrades to websocket shortly after if you look at the network traffic in the browser's debugger.
Is there any reason why you need to connect with websocket from the start? I can implement that if necessary, I guess.
from python-socketio.
I was actually trying to use the library from an iOS client that didn't seem to do the long polling properly. I did leave the browser open for a while, 30s or so, and never saw the upgrade. I will try it again and see.
from python-socketio.
Add engineio_options={'logger': True}
to your Server()
constructor, and then you should see the upgrade in the server console. The upgrade to websocket happens during the first 5-10 seconds.
from python-socketio.
@miguelgrinberg I too am facing same issue when connecting from swift socket-io below is the log.
Steps to recreate
Pythond 2.7.10
created virtual environment and below is python code
from flask import Flask
from flask_socketio import SocketIO, emit
app = Flask(name)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
@socketio.on('connect')
def test_connect():
print('Client connected')
emit('message', {'data': 'Connected'})
@socketio.on('disconnect')
def test_disconnect():
print('Client disconnected')
if name == 'main':
app.debug = True
socketio.run(app, host='127.0.0.1',port=5000, logger=True, engineio_logger=True)
(sandalmatching)INmanjurn:src manjurn$ python WebSocket.py
Server initialized for threading.
- Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
- Restarting with stat
Server initialized for threading.
1639dab20ba94d63bce087ecd26f04e2: Sending packet OPEN with {'pingInterval': 25000, 'pingTimeout': 60000, 'upgrades': [], 'sid': '1639dab20ba94d63bce087ecd26f04e2'}
Client connected
emitting event "message" to 1639dab20ba94d63bce087ecd26f04e2 [/]
1639dab20ba94d63bce087ecd26f04e2: Sending packet MESSAGE with 2["message",{"data":"Connected"}]
1639dab20ba94d63bce087ecd26f04e2: Sending packet MESSAGE with 0
1639dab20ba94d63bce087ecd26f04e2: Received request to upgrade to websocket
127.0.0.1 - - [12/Sep/2015 21:23:14] "GET /socket.io/?transport=websocket HTTP/1.1" 500 -
Traceback (most recent call last):
File "/Users/manjurn/virtualEnv/sandalmatching/lib/python2.7/site-packages/flask/app.py", line 1836, in call
return self.wsgi_app(environ, start_response)
File "/Users/manjurn/virtualEnv/sandalmatching/lib/python2.7/site-packages/engineio/middleware.py", line 32, in call
return self.engineio_app.handle_request(environ, start_response)
File "/Users/manjurn/virtualEnv/sandalmatching/lib/python2.7/site-packages/socketio/server.py", line 305, in handle_request
return self.eio.handle_request(environ, start_response)
File "/Users/manjurn/virtualEnv/sandalmatching/lib/python2.7/site-packages/engineio/server.py", line 215, in handle_request
transport, b64)
File "/Users/manjurn/virtualEnv/sandalmatching/lib/python2.7/site-packages/engineio/server.py", line 280, in _handle_connect
s.handle_get_request(environ, start_response)
File "/Users/manjurn/virtualEnv/sandalmatching/lib/python2.7/site-packages/engineio/socket.py", line 75, in handle_get_request
start_response)
File "/Users/manjurn/virtualEnv/sandalmatching/lib/python2.7/site-packages/engineio/socket.py", line 109, in _upgrade_websocket
self.server.async['websocket_class'])
TypeError: getattr(): attribute name must be string
For the above log i see request for websocket upgrade but it fails.
regards
Manjunath
from python-socketio.
@manju1981 the problem that you have is different than the original report.
The problem @jhorman reported was that it was not possible to connect to the Socket.IO server directly via the websocket transport. This is actually possible in the latest version of the python-engineio package, so that problem is resolved.
Your problem is that you are using the threading asynchronous model, which does not support websocket. If you install the eventlet package the server will automatically use it, and then you will be able to use websocket. Run pip install eventlet
in your virtualenv and let me know if that solves your problem.
from python-socketio.
@miguelgrinberg after your response of threading model i started using eventlet but i was stuck on some issue with requestcontext and hence couldn't respond. I got the issue fixed and its working like a charm.
Steps i followed to resolve this issue
1.Python 2.7.10
2.flask-socketio 1.0a1 and eventlet
I am using swift socket-io client to connect
Below is the python code
import socketio
import eventlet
from flask import Flask
from flask_socketio import emit
sio = socketio.Server()
app = Flask(name)
@sio.on('connect')
def test_connect(arg1, arg2):
print('Client connected')
sio.emit('message', {'data': 'Connected'})
@sio.on('randomEvent')
def testemit(arg1, arg2):
sio.emit('responseevent', {'hi':'manju'})
@sio.on('disconnect')
def test_disconnect(arg):
print('Client disconnected')
if name == 'main':
# wrap Flask application with engineio's middleware
app = socketio.Middleware(sio, app)
# deploy as an eventlet WSGI server
eventlet.wsgi.server(eventlet.listen(('127.0.0.1', 5000)), app)
from python-socketio.
@manju1981 Great, thanks for the feedback.
Since the problem from the OP is now solved, I'm closing this issue.
from python-socketio.
Related Issues (20)
- May need to remove "pip install aioredis" from the documentation
- 5.10.0: pytest is failing HOT 4
- `max_http_buffer_size` value seem ignored by the server HOT 14
- Implementing `__enter__`/`__exit__` on `Client` like `SimpleClient` HOT 2
- Request: type hints (e.g. for mypy) HOT 3
- sio.disconnect() will connect after a connection drop HOT 21
- Update documentation of usage with Gunicorn + gevent/eventlet HOT 5
- Wildcard / catch-all namespace for event handlers HOT 1
- Heroku Problems with Gevent (Request Timeout + Polling Hanging)
- Concurrent broadcasting HOT 2
- All connections stop processing events at the same time
- Session not found when using sio.transport(sid) due to wrong session id HOT 1
- _ping background task not cancelled by async_server.shutdown() HOT 1
- Option to reconnect on initial connection failure
- Value error : Invalid aysnc_mode specified HOT 2
- Python socket ids for client and server dont match. HOT 6
- AsyncServer disconnect event not sent with `aiohttp>=3.9.0` HOT 2
- Test failure with .helpers import AsyncMock HOT 1
- Unable to cancel asynchronous task while client is reconnecting HOT 2
- Namespace catch-all logic HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-socketio.