Skip to content

Commit

Permalink
Replaced gevent, gevent-socketio and gevent-websocket with eventlet,
Browse files Browse the repository at this point in the history
python-socketio and python-engineio, gaining support for Python 3 and
the latest versions of the Socket.IO Javascript client.
  • Loading branch information
miguelgrinberg committed Jul 20, 2015
1 parent 2945f6c commit 883e73e
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 272 deletions.
16 changes: 8 additions & 8 deletions example/app.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from gevent import monkey
monkey.patch_all()
import eventlet
eventlet.monkey_patch()

import time
from threading import Thread
from flask import Flask, render_template, session, request
from flask.ext.socketio import SocketIO, emit, join_room, leave_room, \
close_room, disconnect
from flask_socketio import SocketIO, emit, join_room, leave_room, \
close_room, rooms, disconnect

app = Flask(__name__)
app.debug = True
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
socketio = SocketIO(app, logger=True)
thread = None


Expand Down Expand Up @@ -54,7 +54,7 @@ def join(message):
join_room(message['room'])
session['receive_count'] = session.get('receive_count', 0) + 1
emit('my response',
{'data': 'In rooms: ' + ', '.join(request.namespace.rooms),
{'data': 'In rooms: ' + ', '.join(rooms()),
'count': session['receive_count']})


Expand All @@ -63,7 +63,7 @@ def leave(message):
leave_room(message['room'])
session['receive_count'] = session.get('receive_count', 0) + 1
emit('my response',
{'data': 'In rooms: ' + ', '.join(request.namespace.rooms),
{'data': 'In rooms: ' + ', '.join(rooms()),
'count': session['receive_count']})


Expand Down Expand Up @@ -93,7 +93,7 @@ def disconnect_request():


@socketio.on('connect', namespace='/test')
def test_connect():
def test_connect(env):
emit('my response', {'data': 'Connected', 'count': 0})


Expand Down
18 changes: 9 additions & 9 deletions example/requirements.txt
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
eventlet==0.17.4
Flask==0.10.1
Flask-SocketIO
Jinja2==2.7.2
MarkupSafe==0.18
Werkzeug==0.9.4
gevent==1.0
gevent-socketio==0.3.6
gevent-websocket==0.9.2
greenlet==0.4.2
itsdangerous==0.23
ujson==1.33
greenlet==0.4.7
itsdangerous==0.24
Jinja2==2.7.3
MarkupSafe==0.23
python-engineio==0.3.1
python-socketio==0.1.0
six==1.9.0
Werkzeug==0.10.4
10 changes: 6 additions & 4 deletions example/templates/index.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,26 @@
<head>
<title>Flask-SocketIO Test</title>
<script type="text/javascript" src="//code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
namespace = '/test'; // change to an empty string to use the global namespace

// the socket.io documentation recommends sending an explicit package upon connection
// this is specially important when using the global namespace
var socket = io.connect('http://' + document.domain + ':' + location.port + namespace);
socket.on('connect', function() {
socket.emit('my event', {data: 'I\'m connected!'});
});

// event handler for server sent data
// the data is displayed in the "Received" section of the page
socket.on('my response', function(msg) {
$('#log').append('<br>Received #' + msg.count + ': ' + msg.data);
});

// event handler for new connections
socket.on('connect', function() {
socket.emit('my event', {data: 'I\'m connected!'});
});

// handlers for the different forms in the page
// these send data to the server in a variety of ways
$('form#emit').submit(function(event) {
Expand Down
Loading

1 comment on commit 883e73e

@ktoh
Copy link

@ktoh ktoh commented on 883e73e Aug 10, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am really looking forward to this. eventlet is a solid choice!

Please sign in to comment.