How to use the gevent.server.StreamServer function in gevent

To help you get started, we’ve selected a few gevent examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gevent / gevent / greentest / test__socket_close.py View on Github external
def setUp(self):
        self.server = server.StreamServer(('127.0.0.1', 0), readall)
        self.server.start()
github h0wardch3ng / smartladder / GoAgent+ / proxy.py View on Github external
server = gevent.server.StreamServer((host, int(port)), LightProxyHandler)
        gevent.spawn(server.serve_forever)

    if common.PAC_ENABLE:
        server = gevent.server.StreamServer((common.PAC_IP, common.PAC_PORT), PACServerHandler)
        gevent.spawn(server.serve_forever)

    if common.DNS_ENABLE:
        host, port = common.DNS_LISTEN.split(':')
        server = DNSServer((host, int(port)))
        server.remote_addresses = common.DNS_REMOTE.split('|')
        server.timeout = common.DNS_TIMEOUT
        server.max_cache_size = common.DNS_CACHESIZE
        gevent.spawn(server.serve_forever)

    server = gevent.server.StreamServer((common.LISTEN_IP, common.LISTEN_PORT), GAEProxyHandler)
    server.serve_forever()
github feisuzhu / thbattle / src / start_server.py View on Github external
autoenv.init('Server')

    import settings

    utils.logging.init_server(getattr(logging, options.log.upper()), settings.SENTRY_DSN, settings.VERSION, options.logfile)

    if not options.no_backdoor:
        from gevent.backdoor import BackdoorServer
        gevent.spawn(BackdoorServer((options.backdoor_host, options.backdoor_port)).serve_forever)

    from server.core import Client

    root = logging.getLogger()
    root.info('=' * 20 + settings.VERSION + '=' * 20)
    server = StreamServer((options.host, options.port), Client.serve, None)
    server.serve_forever()
github llpamies / ClusterDFS / clusterdfs / networking.py View on Github external
def __init__(self, handle_class=ServerHandle, addr='', port=7777):
        self.address = (addr,port)
        self.server = gevent.server.StreamServer(self.address,
                                                 self.netser_handle)
        self.handle_class = handle_class
github QuarkChain / pyquarkchain / devp2p / peermanager.py View on Github external
def __init__(self, app):
        log.info('PeerManager init')
        WiredService.__init__(self, app)
        self.peers = []
        self.errors = PeerErrors() if self.config['log_disconnects'] else PeerErrorsBase()

        # setup nodeid based on privkey
        if 'id' not in self.config['p2p']:
            self.config['node']['id'] = crypto.privtopub(
                decode_hex(self.config['node']['privkey_hex']))

        self.listen_addr = (self.config['p2p']['listen_host'], self.config['p2p']['listen_port'])
        self.server = StreamServer(self.listen_addr, handle=self._on_new_connection)
github paypal / support / support / group.py View on Github external
def _init_socket_ark(self, ark_self, ark_peer, ark_secret):
        self.socket_ark = None
        if not ufork:  # proxy for unix system
            return
        self.socket_ark = SocketArk(ark_secret, ark_peer)
        if ark_self:
            sock = self.acquire_server_sock(ark_self)
            self.servers.append(
                gevent.server.StreamServer(
                    sock, self.socket_ark.handle_client, spawn=self.client_pool))
github c00w / bitHopper / bitHopper / pywsgi.py View on Github external
else:
                        env[key] += ',' + value
                else:
                    env[key] = value

        if env.get('HTTP_EXPECT') == '100-continue':
            socket = self.socket
        else:
            socket = None
        chunked = env.get('HTTP_TRANSFER_ENCODING', '').lower() == 'chunked'
        self.wsgi_input = Input(self.rfile, self.content_length, socket=socket, chunked_input=chunked)
        env['wsgi.input'] = self.wsgi_input
        return env


class WSGIServer(StreamServer):
    """A WSGI server based on :class:`StreamServer` that supports HTTPS."""

    handler_class = WSGIHandler
    base_env = {'GATEWAY_INTERFACE': 'CGI/1.1',
                'SERVER_SOFTWARE': 'gevent/%d.%d Python/%d.%d' % (gevent.version_info[:2] + sys.version_info[:2]),
                'SCRIPT_NAME': '',
                'wsgi.version': (1, 0),
                'wsgi.multithread': False,
                'wsgi.multiprocess': False,
                'wsgi.run_once': False}

    def __init__(self, listener, application=None, backlog=None, spawn='default', log='default', handler_class=None,
                 environ=None, **ssl_args):
        StreamServer.__init__(self, listener, backlog=backlog, spawn=spawn, **ssl_args)
        if application is not None:
            self.application = application
github OpenXbox / xbox-smartglass-core-python / xbox / auxiliary / relay.py View on Github external
def __init__(self, connection_info, listen_port):
        if len(connection_info.endpoints) > 1:
            raise Exception('Auxiliary Stream advertises more than one endpoint!')

        self.crypto = AuxiliaryStreamCrypto.from_connection_info(connection_info)
        self.target_ip = connection_info.endpoints[0].ip
        self.target_port = connection_info.endpoints[0].port

        self.console_connection = ConsoleConnection(self.target_ip, self.target_port, self.crypto)
        self.server = StreamServer(('0.0.0.0', listen_port), self._handle_client)
        self.client_socket = None
github decentfox / tulipcore / examples / echoserver.py View on Github external
while True:
        line = fileobj.readline()
        if not line:
            print("client disconnected")
            break
        if line.strip().lower() == b'quit':
            print("client quit")
            break
        fileobj.write(line)
        fileobj.flush()
        print("echoed %r" % line)


if __name__ == '__main__':
    # to make the server use SSL, pass certfile and keyfile arguments to the constructor
    server = StreamServer(('0.0.0.0', 6000), echo)
    # to start the server asynchronously, use its start() method;
    # we use blocking serve_forever() here because we have no other jobs
    print('Starting echo server on port 6000')
    server.serve_forever()