Exemplo n.º 1
0
 def __init__(self, addr=None, port=None, sock=None):
     self._loop = asyncio.get_event_loop()
     if sock is None:
         pf = lambda: ServerRpc(self._handler)
         self._server_mode = True
         self._protocol = self._loop.run_until_complete(
             self._loop.create_server(pf, addr, port))
     else:
         pf = lambda: ServerRpc(self._handler, self._connection_lost)
         self._server_mode = False
         _, self._protocol = self._loop.run_until_complete(
             self._loop.create_connection(pf, sock=sock))
         self._close_fut = asyncio.Future(loop=self._loop)
Exemplo n.º 2
0
 def __init__(self, addr=None, port=None, sock=None, rpc_type='json',
              notification_handler=None):
     self._addr = addr
     self._port = port
     self._loop = asyncio.get_event_loop()
     self._protocol = None
     self._conn_timeout = 60
     self._waiting = {}
     rpc_cls = JsonRpc
     if rpc_type == 'msgpack':
         rpc_cls = MsgPackRpc
     self._create_rpc = lambda: ClientRpc(
         rpc_cls(), self._handler, notification_handler,
         self._error, self._connection_lost)
     if sock is not None:
         fut = self._loop.create_connection(self._create_rpc, sock=sock)
         _, self._protocol = self._loop.run_until_complete(fut)
     self._lock = asyncio.Lock()
     self._close_fut = None
Exemplo n.º 3
0
import sys
import time

from asynciorpc import asyncio
from asynciorpc.client import Client
from asynciorpc.server import Server

addr = '127.0.0.1'
port = 8888
loop = asyncio.get_event_loop()


def run_server():
    class EchoServer(Server):
        def _handler(self, name, *args, **kwargs):
            return args[0]

    if True:
        server = EchoServer(addr, port)
        print('running server...')
        try:
            loop.run_forever()
        except KeyboardInterrupt:
            pass
    else:
        import socket
        server = socket.socket()
        server.bind((addr, port))
        server.listen(1)
        while True:
            try: