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

Websocket connection is not working #241

Closed
ihrigb opened this issue Mar 16, 2016 · 3 comments
Closed

Websocket connection is not working #241

ihrigb opened this issue Mar 16, 2016 · 3 comments
Labels

Comments

@ihrigb
Copy link

ihrigb commented Mar 16, 2016

I have problems establishing a websocket connection. This issue should be related to an Issue on Stackoverflow.
For testing-purposes I have the following small flask app:

from flask import Flask, render_template
from flask_socketio import SocketIO, emit

app = Flask(__name__)
socketio = SocketIO(app)

@socketio.on('connect')
def connect():
    print('Connect')

@app.route('/')
def index():
    return render_template('app.html')

if __name__ == '__main__':
    socketio.run(app, host='0.0.0.0', debug=True)

The server commes up but engaging a websocket connection does not work

var socket = new WebSocket('ws://localhost:5000');

This JS call causes server side exception:

(6192) accepted ('127.0.0.1', 64292)
127.0.0.1 - - [16/Mar/2016 23:13:12] "GET /socket HTTP/1.1" 404 342 0.000000
Traceback (most recent call last):
  File "C:\Users\Benjamin\AppData\Local\Programs\Python\Python35\lib\site-packages\eventlet\greenpool.py", line 82, in _spawn_n_impl
    func(*args, **kwargs)
  File "C:\Users\Benjamin\AppData\Local\Programs\Python\Python35\lib\site-packages\eventlet\wsgi.py", line 719, in process_request
    proto.__init__(sock, address, self)
  File "C:\Users\Benjamin\AppData\Local\Programs\Python\Python35\lib\socketserver.py", line 684, in __init__
    self.handle()
  File "C:\Users\Benjamin\AppData\Local\Programs\Python\Python35\lib\http\server.py", line 417, in handle
    self.handle_one_request()
  File "C:\Users\Benjamin\AppData\Local\Programs\Python\Python35\lib\site-packages\eventlet\wsgi.py", line 330, in handle_one_request
    self.raw_requestline = self.rfile.readline(self.server.url_length_limit)
OSError: raw readinto() returned invalid length -1 (should have been between 0 and 8192)

and client side exception:

WebSocket connection to 'ws://localhost:5000/socket' failed: Error during WebSocket handshake: Unexpected response code: 404
@ihrigb
Copy link
Author

ihrigb commented Mar 16, 2016

FYI: pip freeze gives following output:

eventlet==0.18.4
Flask==0.10.1
Flask-SocketIO==2.2
gevent==1.1.0
gevent-websocket==0.9.5
greenlet==0.4.9
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
Pygments==2.1.3
pyserial==3.0.1
python-engineio==0.9.0
python-socketio==1.1
six==1.10.0
virtualenv==15.0.0
Werkzeug==0.11.4

@miguelgrinberg
Copy link
Owner

SocketIO is not the same as WebSocket. To connect to a SocketIO server you need to use a SocketIO client. See the Javascript code in the example included in this repository for an example.

@ihrigb
Copy link
Author

ihrigb commented Mar 17, 2016

Ok, thanks for the info! That was not obvious for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants