1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
from __future__ import print_function
import Pyro4
import Pyro4.constants
secret_code = "pancakes"
class CustomDaemon(Pyro4.Daemon):
def validateHandshake(self, conn, data):
print("Daemon received handshake request from:", conn.sock.getpeername())
print("Handshake data:", data)
# if needed, you can inspect Pyro4.current_context
if data == secret_code:
print("Secret code okay! Connection accepted.")
# return some custom handshake data:
return ["how", "are", "you", "doing"]
else:
print("Secret code wrong! Connection refused.")
raise ValueError("wrong secret code, connection refused")
def clientDisconnect(self, conn):
print("Daemon client disconnects:", conn.sock.getpeername())
with CustomDaemon() as daemon:
print("Server is ready. You can use the following URI to connect:")
print(daemon.uriFor(Pyro4.constants.DAEMON_NAME))
print("When asked, enter the following secret code: ", secret_code)
daemon.requestLoop()
|