Name | Modified | Size | Downloads / Week |
---|---|---|---|
Parent folder | |||
README | 2001-10-28 | 1.3 kB | |
env.py | 2001-10-28 | 7.1 kB | |
Totals: 2 Items | 8.3 kB | 0 |
Here's how to use it: (In order to keep the output legible, I usually run each environment in it's own instance of the python interpreter) #import the module import env # make an environment instance with # Id = "Alice" which listens to port 10000 on the local host, # and that knows about a single peer "Bob" # which it expects to be listening on port 10001 # (see the code in env.py for details, it's pretty simple) a = env.alice() # makes "Bob" on port 10001 # who knows about "Charlie" on port 10002 b = env.bob() # start Alice's thread, it will begin requesting # peers and pings from its peers, as well as # replying to responses a.start() # start Bob's thread, Bob will begin responding to # Alice's requests b.start() You should see some debugging messages, when requests and responses are received. Alice should discover Charlie as a peer, and periodically update the pingtime. There are more conveinience methods for creating more environments: env.charlie() # knows about "David" env.david() # knows about "Elmo" env.elmo() # knows about "Alice" Elmo sets up a loop where eventually everybody knows about everybod else... The entry point to the main thread is the method environment.run(), if you are interested in the code.