Exemplo n.º 1
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
Exemplo n.º 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
Exemplo n.º 4
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()
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 7
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()

Exemplo n.º 8
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()
        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()