5 import asyncio
.exceptions
10 log1
=logging
.getLogger(__name__
)
15 def __init__(self
,host
:str,port
:int):
18 self
.ctxs
:typing
.List
[server
.ServerContext
]=[]
21 async def __newConnectionHandler(self
,r
:asyncio
.StreamReader
,w
:asyncio
.StreamWriter
):
23 ctx
=server
.ServerContext()
27 ctx
.funcMap
.update(self
.funcMap
)
29 except asyncio
.exceptions
.IncompleteReadError
:
30 log1
.debug('connection closed')
31 except Exception as exc
:
32 log1
.debug('server exception:%s',traceback
.format_exc())
38 async def start(self
):
39 self
.srv1
:asyncio
.AbstractServer
=await asyncio
.start_server(self
.__newConnectionHandler
,self
.host
,self
.port
)
54 def __init__(self
,host
:str,port
:int):
58 async def start(self
):
59 r
,w
=await asyncio
.open_connection(self
.host
,self
.port
)
60 self
.rpcconn
=client
.RpcConnection()
61 self
.rpcconn
.backend1(r
,w
)
62 self
.runtask
=asyncio
.create_task(self
.rpcconn
.run())
67 self
.rpcconn
.running
=False
70 await self
.rpcconn
.close()