예제 #1
0
    def main(self, host, port):
        got_request_exception.connect(exception_printer)

        self.stdout.write('Serving at {host}:{port}\n'.format(host = host, port = port))
        application = WSGIHandler()
        server = SocketIOServer((host, port), application, namespace = 'socket.io', policy_server = False)
        server.serve_forever()
예제 #2
0
    def handle(self, addrport="", *args, **options):

        if not addrport:
            self.addr = HOST
            self.port = PORT
        else:
            m = match(naiveip_re, addrport)
            if m is None:
                raise CommandError('"%s" is not a valid port number '
                                   'or address:port pair.' % addrport)
            self.addr, _, _, _, self.port = m.groups()

        # Make the port available here for the path:
        #   socketio_tags.socketio ->
        #   socketio_scripts.html ->
        #   io.Socket JS constructor
        # allowing the port to be set as the client-side default there.
        environ["DJANGO_SOCKETIO_PORT"] = str(self.port)

        start_new_thread(reload_watcher, ())
        try:
            bind = (self.addr, int(self.port))
            print
            print "SocketIOServer running on %s:%s" % bind
            print
            handler = self.get_handler(*args, **options)
            server = SocketIOServer(bind, handler, resource="socket.io")
            server.serve_forever()
        except KeyboardInterrupt:
            if RELOAD:
                print
                print "Reloading..."
                restart_with_reloader()
            else:
                raise
    def handle(self, addrport="", *args, **options):

        if not addrport:
            self.addr = "127.0.0.1"
            self.port = 9000
        else:
            m = match(naiveip_re, addrport)
            if m is None:
                raise CommandError('"%s" is not a valid port number '
                                   'or address:port pair.' % addrport)
            self.addr, _, _, _, self.port = m.groups()

        start_new_thread(reload_watcher, ())
        try:
            bind = (self.addr, int(self.port))
            print
            print "SocketIOServer running on %s:%s" % bind
            print
            handler = self.get_handler(*args, **options)
            server = SocketIOServer(bind, handler, resource="socket.io")
            server.serve_forever()
        except KeyboardInterrupt:
            if RELOAD:
                print
                print "Reloading..."
                restart_with_reloader()
            else:
                raise
예제 #4
0
    def handle(self, addrport="", *args, **options):

        if not addrport:
            self.addr = HOST
            self.port = PORT
        else:
            m = match(naiveip_re, addrport)
            if m is None:
                raise CommandError('"%s" is not a valid port number '
                                   'or address:port pair.' % addrport)
            self.addr, _, _, _, self.port = m.groups()

        # Make the port available here for the path:
        #   socketio_tags.socketio ->
        #   socketio_scripts.html ->
        #   io.Socket JS constructor
        # allowing the port to be set as the client-side default there.
        environ["DJANGO_SOCKETIO_PORT"] = str(self.port)

        start_new_thread(reload_watcher, ())
        try:
            bind = (self.addr, int(self.port))
            print
            print "SocketIOServer running on %s:%s" % bind
            print
            handler = self.get_handler(*args, **options)
            server = SocketIOServer(bind, handler, resource="socket.io")
            server.serve_forever()
        except KeyboardInterrupt:
            if RELOAD:
                print
                print "Reloading..."
                restart_with_reloader()
            else:
                raise
예제 #5
0
    def main():
        # Load application and config.
        app = loadapp('config:%s' % cfgfile, relative_to='.')
        server = SocketIOServer((host, port), app,
                                namespace="socket.io")

        try:
            print "Serving on %s:%d (http://127.0.0.1:%d) ..." % (host, port, port)
            server.serve_forever()
        except socket.error, e:
            print "ERROR SERVING WSGI APP: %s" % e
            sys.exit(1)
예제 #6
0
    def main():
        # Load application and config.
        app = loadapp('config:%s' % cfgfile, relative_to='.')
        server = SocketIOServer((host, port), app, resource="socket.io")

        try:
            print "Serving on %s:%d (http://127.0.0.1:%d) ..." % (host, port,
                                                                  port)
            server.serve_forever()
        except socket.error, e:
            print "ERROR SERVING WSGI APP: %s" % e
            sys.exit(1)
예제 #7
0
 def run(self):
     # while True:
     self.logger = logging.getLogger("socketio_server")
     self.logger.info("Creating websocket-server")
     SocketIOServer((settings.SOCKETIO_HOST, settings.SOCKETIO_PORT),
                    application,
                    resource="socket.io",
                    log=StdErrWrapper()).serve_forever()
     self.logger.info("Done.")
예제 #8
0
    def run(self, *args, **options):
        # use gevent to patch the standard lib to get async support
        monkey.patch_all()

        server_address = (self.addr, self.port)

        print "Socket.IO server started on %s:%s" % server_address
        SocketIOServer(server_address,
                       self.get_handler(),
                       resource="socket.io").serve_forever()
예제 #9
0
    def handle(self, *args, **options):
        """Run gevent socketio server."""
        try:
            port = int(args[0])
        except:
            port = 8000

        # Make blocking calls in socket lib non-blocking:
        monkey.patch_all()

        # Start up gevent-socketio stuff
        application = WSGIHandler()
        print 'Listening on http://127.0.0.1:%s and on port 843 (flash policy server)' % port
        SocketIOServer(('', port), application,
                       resource='socket.io').serve_forever()
예제 #10
0
def main():
	app = make_wsgi_app({})
	server = SocketIOServer(('0.0.0.0', 6543), app, namespace='socket.io', policy_server=False)
	print 'HTTP Listening on port 6543'
	server.serve_forever()
예제 #11
0
 def serve(app):
     reinit()
     patch_all(dns=False)
     print "Serving on %s:%d (http://127.0.0.1:%d) ..." % (host, port, port)
     SocketIOServer((host, port), app,
                    resource=resource).serve_forever()
예제 #12
0
#!/usr/bin/env python

PORT = 9000

import os

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

from socketio import SocketIOServer

if __name__ == '__main__':
    print 'Listening on port %s and on port 843 (flash policy server)' % PORT
    SocketIOServer(('', PORT), application, resource="socket.io").serve_forever()
예제 #13
0
import eventlet
eventlet.monkey_patch()

import time
from threading import Thread
import eventlet
from eventlet import wsgi
from flask import Flask, render_template
from socketio import Server as SocketIOServer
from socketio import Middleware as SocketIOMiddleware

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


def background_thread():
    """Example of how to send server generated events to clients."""
    count = 0
    while True:
        time.sleep(10)
        count += 1
        socketio.emit('my response', {'data': 'Server generated event'},
                      namespace='/test')


@app.route('/')
def index():
    global thread
예제 #14
0
                    message = message[0]
                    message = {
                        'message': [socketio.session.session_id, message]
                    }
                    self.buffer.append(message)
                    if len(self.buffer) > 15:
                        del self.buffer[0]
                    socketio.broadcast(message)
                else:
                    if not socketio.connected():
                        socketio.broadcast({
                            'announcement':
                            socketio.session.session_id + ' disconnected'
                        })

            return []

        else:
            return not_found(start_response)


def not_found(start_response):
    start_response('404 Not Found', [])
    return ['<h1>Not Found</h1>']


if __name__ == '__main__':
    print 'Listening on port 8080 and on port 843 (flash policy server)'
    SocketIOServer(('', 8080), Application(),
                   resource="socket.io").serve_forever()
예제 #15
0
    @csrf_protected
    def POST(myself):
        input_data = web.input()
        selected_room = input_data["room"]
        data = {"action": "system", "message": input_data["message"]}
        try:
            if selected_room:
                broadcast_channel(data, channel="room-" + selected_room)
            else:
                broadcast(data)
        except NoSocket, e:
            message = e
        else:
            message = "Message sent"
        rooms = chat_db.select("chat_chatroom")
        return my_render.render("system_message", **locals())


SOCKETIO_HOST = ""
SOCKETIO_PORT = 8000
application = app.wsgifunc()

import events

if __name__ == "__main__":
    print 'Listening on http://127.0.0.1:%s and on port 843 (flash policy server)' % SOCKETIO_PORT
    SocketIOServer((SOCKETIO_HOST, SOCKETIO_PORT),
                   application,
                   resource="socket.io").serve_forever()
예제 #16
0
파일: serve.py 프로젝트: sontek/pycon2012
from socketio import SocketIOServer
from pyramid.paster import get_app
from gevent import monkey
monkey.patch_all()

if __name__ == '__main__':

    app = get_app('development.ini')
    print 'Listening on port http://127.0.0.1:8080 and on port 843 (flash policy server)'
    SocketIOServer(('127.0.0.1', 8080),
                   app,
                   namespace="socket.io",
                   policy_server=False).serve_forever()
예제 #17
0
#!/usr/bin/env python
PORT = 9000

from re import match
from thread import start_new_thread
from time import sleep
from os import getpid, kill, environ
from signal import SIGINT

from django.conf import settings
from django.core.handlers.wsgi import WSGIHandler
from django.core.management.base import BaseCommand, CommandError
from django.utils.autoreload import code_changed, restart_with_reloader
from socketio import SocketIOServer

from django_socketio.clients import client_end_all

DJANGO_SETTINGS_MODULE = 'politcally-correct.settings'

if __name__ == '__main__':
    addr = "127.0.0.1"
    port = PORT
    bind = (addr, int(port))
    print
    print "SocketIOServer running on %s:%s" % bind
    print
    handler = WSGIHandler()
    server = SocketIOServer(bind, handler, resource="socket.io")
    server.serve_forever()

        if path.startswith('/__main__'):
            return self._main(request)

        if path.startswith('/__lib__'):
            return self._lib(request)

        # pre-matching
        parts = [part for part in path.split('/') if part != '']
        if len(parts) > 0:
            for root, app in self.appviews:
                if parts[0] == root.lstrip('/'):
                    return app(request)

        return self._404()

    def _404(self):
        tmpl = os.path.join(_HERE, 'templates', '404.mako')
        with open(tmpl) as f:
            tmpl = Template(f.read())
        body = tmpl.render()
        return Response(status=404, body=body)


if __name__ == '__main__':
    from socketio import SocketIOServer
    app = WebApp([sys.argv[1:]])
    server = SocketIOServer(('', 8000), app, resource='socket.io')
    print("Serving on port 8000...")
    server.serve_forever()