Jeffrey Gelens avatar Jeffrey Gelens committed 1907254

.

Comments (0)

Files changed (3)

examples/websocket.html

         s.send('hi');
     };
     s.onmessage = function(e) {
-      //alert('got ' + e.data);
+
+      alert('got ' + e.data);
       var lines = e.data.split('\n');
       for (var i = 0; i < lines.length - 1; i++) {
         var parts = lines[i].split(' ');

geventwebsocket/handler.py

     """ Automatically upgrades the connection to websockets. """
 
     GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
-    SUPPORTED_VERSIONS = (7,)
+    SUPPORTED_VERSIONS = (7,8)
 
     def __init__(self, *args, **kwargs):
         self.websocket_connection = False
             self.websocket = WebSocketVersion7(self.socket, self.rfile, self.environ)
 
             if int(version) in self.SUPPORTED_VERSIONS:
+                self._handshake_version7()
                 return True
             else:
                 pass
         environ = self.environ
 
         protocol, version = self.request_version.split("/")
-        key = environ.get("HTTP_SEC_WEBSOCKET_KEY")
+        key = environ.get("HTTP_SEC_WEBSOCKET_KEY").replace(" ", "")
+
+        print key
 
         # check client handshake for validity
         if not environ.get("REQUEST_METHOD") == "GET":
             self._close_connection()
             return False
 
+        headers = [
+            ("Upgrade", "websocket"),
+            ("Connection", "Upgrade"),
+            ("Sec-WebSocket-Accept", b64encode(sha1(key + self.GUID).digest())),
+        ]
+        self.start_response("101 Switching Protocols", headers)
+        print headers
+        return True
+
+
 
     def _handshake_hybi06(self):
         raise Exception("Version not yet supported")

geventwebsocket/websocket.py

             # this can't really happen, but for correctness sake...
             raise Exception('Message is too long')
 
+        print preamble, message
+
         self.socket.sendall(preamble + message)
 
     def close(self, reason, message):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.