Update RPC with simpler methods for connecting
This commit is contained in:
@@ -32,8 +32,8 @@ at the given address and does some RPCs')
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main(sock):
|
||||
client = capnp.TwoPartyClient(sock)
|
||||
def main(host):
|
||||
client = capnp.TwoPartyClient(host)
|
||||
|
||||
# Pass "calculator" to ez_restore (there's also a `restore` function that
|
||||
# takes a struct or AnyPointer as an argument), and then cast the returned
|
||||
@@ -282,11 +282,4 @@ def main(sock):
|
||||
print("PASS")
|
||||
|
||||
if __name__ == '__main__':
|
||||
host, port = parse_args().host.split(':')
|
||||
|
||||
sock = socket.create_connection((host, port))
|
||||
|
||||
# Set TCP_NODELAY on socket to disable Nagle's algorithm. This is not
|
||||
# neccessary, but it speeds things up.
|
||||
sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
main(sock)
|
||||
main(parse_args().host)
|
||||
|
||||
@@ -138,35 +138,8 @@ def restore(ref):
|
||||
def main():
|
||||
address = parse_args().address
|
||||
|
||||
if ':' in address:
|
||||
address, port = address.split(':')
|
||||
port = int(port)
|
||||
else:
|
||||
port = random.randint(60000, 61000)
|
||||
|
||||
if address == '*':
|
||||
address = ''
|
||||
|
||||
print("Listening on port: {}".format(port))
|
||||
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
# Set TCP_NODELAY on socket to disable Nagle's algorithm. This is not
|
||||
# neccessary, but it speeds things up.
|
||||
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
|
||||
s.bind((address, port))
|
||||
s.listen(1) # service only 1 client at a time
|
||||
|
||||
while True:
|
||||
try:
|
||||
(clientsocket, address) = s.accept()
|
||||
server = capnp.TwoPartyServer(clientsocket, restore)
|
||||
|
||||
server.run_forever()
|
||||
print("client disconnected")
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
server = capnp.TwoPartyServer(address, restore)
|
||||
server.run_forever()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user