2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-26 03:38:25 +08:00

pc_rpc: add init magic string

This commit is contained in:
Sebastien Bourdeauducq 2014-11-20 14:21:41 -08:00
parent 914bdd95d5
commit 64866a0f49

View File

@ -29,6 +29,9 @@ class IncompatibleServer(Exception):
pass pass
_init_string = b"ARTIQ pc_rpc\n"
class Client: class Client:
"""This class proxies the methods available on the server so that they """This class proxies the methods available on the server so that they
can be used as if they were local methods. can be used as if they were local methods.
@ -59,6 +62,7 @@ class Client:
""" """
def __init__(self, host, port, expected_id_type): def __init__(self, host, port, expected_id_type):
self.socket = socket.create_connection((host, port)) self.socket = socket.create_connection((host, port))
self.socket.sendall(_init_string)
self._identify(expected_id_type) self._identify(expected_id_type)
def get_rpc_id(self): def get_rpc_id(self):
@ -176,6 +180,9 @@ class Server:
@asyncio.coroutine @asyncio.coroutine
def _handle_connection_task(self, reader, writer): def _handle_connection_task(self, reader, writer):
try: try:
line = yield from reader.readline()
if line != _init_string:
return
while True: while True:
line = yield from reader.readline() line = yield from reader.readline()
if not line: if not line: