Reputation: 376
When connecting to my WebSocket I get the error mentioned above, right after the client connects.
2015-09-06 12:01:12-0400 [-] reactor class: twisted.internet.epollreactor.EPollReactor.
2015-09-06 12:01:12-0400 [-] ServerFactory starting on 1025
2015-09-06 12:01:12-0400 [-] Starting factory <twisted.internet.protocol.ServerFactory instance at 0x1f92f80>
2015-09-06 12:01:28-0400 [-] Got new client!
2015-09-06 12:01:28-0400 [-] received 'GET / HTTP/1.1'
2015-09-06 12:01:28-0400 [-] received 'Host: ip:1025'
2015-09-06 12:01:28-0400 [-] received 'Connection: Upgrade'
2015-09-06 12:01:28-0400 [-] received 'Pragma: no-cache'
2015-09-06 12:01:28-0400 [-] received 'Cache-Control: no-cache'
2015-09-06 12:01:28-0400 [-] received 'Upgrade: websocket'
2015-09-06 12:01:28-0400 [-] received 'Origin: http://server-ip.net'
2015-09-06 12:01:28-0400 [-] received 'Sec-WebSocket-Version: 13'
2015-09-06 12:01:28-0400 [-] received 'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36'
2015-09-06 12:01:28-0400 [-] received 'Accept-Encoding: gzip, deflate, sdch'
2015-09-06 12:01:28-0400 [-] received 'Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4'
2015-09-06 12:01:28-0400 [-] received 'Sec-WebSocket-Key: Au1JIvJG0A2Jep3+wqCPRg=='
2015-09-06 12:01:28-0400 [-] received 'Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits'
2015-09-06 12:01:28-0400 [-] received ''
2015-09-06 12:01:28-0400 [-] Lost a client!
On the client side it looks like this:
WebSocket connection to 'ws://server-ip:1025/' failed: Error during WebSocket handshake: Invalid status line
What I have been trying to do:
I followed this tutorial to create a real-time chat (with Django). The chatserver.py I am using is coming directly from their docu: https://twistedmatrix.com/documents/current/_downloads/chatserver.py . The rest (jQuery script etc.) is as it is in that tutorial.
Upvotes: 1
Views: 3318
Reputation: 4798
That MyChat.lineReceived
sends the message to every connected client including itself. I expect that means it'll echo all those headers it received right back to the WebSocket client, which is probably not what it expects.
The ferritfarmer tutorial you linked to handles this by wrapping that MyChat's factory in a WebsocketResource
, a modification from the chatserver.py
you linked to straight from the normal Twisted example.
I believe that WebsocketResource comes from the specific development branch of Twisted the tutorial links to. Unfortunately that branch appears to be stagnant. I hear Autobahn's WebSocket implementation is a good place to look instead.
Upvotes: 1