Git Product home page Git Product logo

gevent_socketio2's Introduction

Introduction

SocketIO Server implementation under gevent, at first I tried to make a pull to gevent-socketio to support 1.0, but the code changed dramatically, and it is better to start as a new project and rewrite all the codes.

Now the library is still in development.

Sample Project

sample project [https://github.com/shuoli84/django_socketio_test]

Installation

pip install gevent_socketio2

Features

Most of socketio 1.0 features but ACK, BINARY_ACK. The reason why those not supported yet is I didn't use them in my project, if you need this, open a issue or make a pull request, I am more than happy to merge it.

Usage

Django + gevent

After installation

add 'socketio' to INSTALLED_APPS
create a custom command "run.py" under rootapp/management/commands/
# coding=utf-8
import os
from socketio.server import serve

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_socketio_test.settings")
from django.core.management.base import BaseCommand


class Command(BaseCommand):
    def handle(self, *args, **options):
        from django.core.wsgi import get_wsgi_application
        application = get_wsgi_application()
        serve(application, host='127.0.0.1', port='8001')  # Use our server to hook things up

In your urls.py, add

url(r'^socket\.io/', include(urls)),  # Used to attach framework specific request to socket

in any app, create a file "sockets.py"

from socketio.decorators import namespace

@namespace('/echo')
class EchoNamespace(object):
    clients = {}

    @classmethod
    def on_connect(cls, socket):
        print 'on connect'
        if socket.id not in cls.clients:
            cls.clients[socket.id] = socket

        if cls.job is None:
            cls.job = gevent.spawn(cls.send_picture)

    @classmethod
    def on_disconnect(cls, socket):
        cls.clients.pop(socket.id, None)

    @classmethod
    def on_message(cls, socket, message):
        print 'received new message %s' % message
        logger.info('received new message %s', message)
        socket.namespace.emit('message', message)

run

python manage.py run

Server supports

Gevent

Gunicorn

[Other wsgi based server could be added easily]

gevent_socketio2's People

Contributors

shuoli84 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gevent_socketio2's Issues

Status of this library?

Just discovered this project - seems great, as the original gevent-socketio is dead. What is the status of this project? Is it usable already? Anyone using it in production?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.