Jeffrey Gelens avatar Jeffrey Gelens committed db36f8f

Test files

Comments (0)

Files changed (4)

-=================
-_gevent-websocket
-=================
+================
+gevent-websocket
+================
 
-_gevent-websocket is a websocket library for the Gevent networking library.
-
-_gevent-websocket is written and maintained by `Jeffrey Gelens`_ and licensed
-under the BSD license.
+`gevent-websocket`_ is a websocket library for the Gevent networking library
+written written and maintained by `Jeffrey Gelens`_ It is licensed under the BSD license.
 
 Installation
 ------------------------
 
 Install Python 2.4 or newer and gevent and its dependencies. The latest release
-can be download from _PyPi or by cloning the _repository.
+can be download from PyPi_ or by cloning the repository_.
 
 Usage
 -----
 server. Set the `handler_class` when creating a pywsgi server instance to make
 use of the Websocket functionality:
 
-..
+.. sourcecode:: python
+
     from gevent import pywsgi
     from geventwebsocket.handler import WebSocketHandler
 
 
 Afterwards write a WSGI application with a 3rd parameter, namely a websocket instance:
 
-..
+.. sourcecode:: python
+
     def websocket_app(environ, start_response, ws):
         if ws.path == '/echo':
             message = ws.wait()
 websocket_app from the previous example is required to start the server.
 Dtart Gunicorn using the following command and worker class:
 
-..
+.. sourcecode:: python
+
     gunicorn -k "geventwebsocket.gunicorn.workers.GeventWebSocketWorker" gunicorn_websocket:websocket_app
 
 .. _gevent-websocket: http://www.bitbucket.org/Jeffrey/gevent-websocket/

examples/gunicorn_websocket.py

+# -*- coding: utf-8 -
+#
+# gunicorn -k "geventwebsocket.gunicorn.workers.GeventWebSocketWorker" gunicorn_websocket:app
+
+import gevent
+
+# demo app
+import os
+import random
+def app(environ, start_response, ws=None):
+    if ws.path == '/echo':
+        while True:
+            m = ws.wait()
+            if m is None:
+                break
+            ws.send(m)
+
+    elif ws.path == '/data':
+        for i in xrange(10000):
+            ws.send("0 %s %s\n" % (i, random.random()))
+            gevent.sleep(1)
+from geventwebsocket.handler import WebSocketHandler
+from gevent import pywsgi
+import gevent
+
+
+# demo app
+import os
+import random
+def handle(environ, start_response, ws):
+    """  This is the websocket handler function.  Note that we
+    can dispatch based on path in here, too."""
+    if ws.path == '/echo':
+        while True:
+            m = ws.wait()
+            if m is None:
+                break
+            ws.send(m)
+
+    elif ws.path == '/data':
+        for i in xrange(10000):
+            ws.send("0 %s %s\n" % (i, random.random()))
+            #print "0 %s %s\n" % (i, random.random())
+            gevent.sleep(0.1)
+
+server = pywsgi.WSGIServer(('0.0.0.0', 9999), handle,
+        handler_class=WebSocketHandler)
+server.serve_forever()

examples/websocket.html

+<!DOCTYPE html>
+<html>
+<head>
+<!-- idea and code swiped from
+http://assorted.svn.sourceforge.net/viewvc/assorted/real-time-plotter/trunk/src/rtp.html?view=markup -->
+<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
+<script src="http://people.iola.dk/olau/flot/jquery.flot.js"></script>
+<script>
+var iets = "";
+window.onload = function() {
+    var data = {};
+    var s = new WebSocket("ws://localhost:8000/data");
+    s.onopen = function() {
+        //alert('open');
+        s.send('hi');
+    };
+    s.onmessage = function(e) {
+      //alert('got ' + e.data);
+      var lines = e.data.split('\n');
+      for (var i = 0; i < lines.length - 1; i++) {
+        var parts = lines[i].split(' ');
+        var d = parts[0], x = parseFloat(parts[1]), y = parseFloat(parts[2]);
+        if (!(d in data)) data[d] = [];
+        data[d].push([x,y]);
+      }
+      var plots = [];
+      for (var d in data) plots.push( { data: data[d].slice(data[d].length - 200) } );
+      $.plot( $("#holder"), plots,
+              {
+                series: {
+                  lines: { show: true, fill: true },
+                },
+                yaxis: { min: 0 },
+              } );
+
+      s.send('');
+    };
+};
+</script>
+</head>
+<body>
+<h3>Plot</h3>
+<div id="holder" style="width:600px;height:300px"></div>
+</body>
+</html>
+
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.