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

various suggested fixes #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
Empty file added __init__.py
Empty file.
7 changes: 6 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
<script language='javascript'>

$(document).ready(function() {
var ws = new WebSocket("ws://localhost:8080/test");
var ws;
if (typeof MozWebSocket != "undefined") {
ws = new MozWebSocket("ws://localhost:8080/test");
} else {
ws = new WebSocket("ws://localhost:8080/test");
}
ws.onmessage = function(evt) {
$('#output').text(evt.data);
}
Expand Down
11 changes: 6 additions & 5 deletions websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,18 @@ def _getOneHeader(self, name):

def _clientHandshakeHybi(self):
"""
Initial handshake, as defined in hybi-10.
Initial handshake, as defined in hybi-10 and 16 (versions 8 and 13).

If the client is not following the hybi-10 protocol or is requesting a
If the client is not following the hybi-10 or 16 protocol or is requesting a
version that's lower than what hybi-10 describes, the connection will
be closed.

Otherwise the appropriate transport and content decoders will be
plugged in and the connection will be estabilished.
"""
version = self._getOneHeader("Sec-WebSocket-Version")
# we only speak version 8 of the protocol
if version != "8":
# we only speak version 7, 8 and 13 of the protocol
if version not in ("7", "8", "13"):
self.setResponseCode(426, "Upgrade Required")
self.setHeader("Sec-WebSocket-Version", "8")
return self.finish()
Expand Down Expand Up @@ -523,7 +523,8 @@ def sendFrame(self, opcode, payload, fragmented=False):

data.append(length)
header = struct.pack(spec, *data)
self._request.write(header + payload)
if self._connected:
self._request.write(header + payload)


class WebSocketHandler(object):
Expand Down