|
@@ -106,6 +106,7 @@ class NetMsg:
|
|
|
"""The parent class of network messages. Subclass this class to
|
|
|
implement specific kinds of network messages."""
|
|
|
|
|
|
+
|
|
|
class StringNetMsg(NetMsg):
|
|
|
"""Send an arbitratry string as a NetMsg."""
|
|
|
def __init__(self, str):
|
|
@@ -114,6 +115,7 @@ class StringNetMsg(NetMsg):
|
|
|
def __str__(self):
|
|
|
return self.data.__str__()
|
|
|
|
|
|
+
|
|
|
class Connection:
|
|
|
def __init__(self, peer = None):
|
|
|
"""Create a Connection object with the given peer."""
|
|
@@ -128,10 +130,13 @@ class Connection:
|
|
|
self.peer.closed()
|
|
|
self.peer = None
|
|
|
|
|
|
+
|
|
|
class ClientConnection(Connection):
|
|
|
"""The parent class of client-side network connections. Subclass
|
|
|
this class to do anything more elaborate than just passing arbitrary
|
|
|
- NetMsgs, which then get ignored."""
|
|
|
+ NetMsgs, which then get ignored. Use subclasses of this class when
|
|
|
+ the server required no per-connection state, such as just fetching
|
|
|
+ consensus documents."""
|
|
|
|
|
|
def __init__(self, peer):
|
|
|
"""Create a ClientConnection object with the given peer. The
|
|
@@ -163,6 +168,7 @@ class ServerConnection(Connection):
|
|
|
def received(self, client, netmsg):
|
|
|
print("received", netmsg, "from client", client)
|
|
|
|
|
|
+
|
|
|
class Server:
|
|
|
"""The parent class of network servers. Subclass this class to
|
|
|
implement servers of different kinds. You will probably only need
|
|
@@ -196,6 +202,7 @@ class Server:
|
|
|
serverconnection.peer = clientconnection
|
|
|
return clientconnection
|
|
|
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
|
n1 = NetAddr()
|
|
|
n2 = NetAddr()
|