Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/sugar/p2p
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2006-06-27 16:03:06 (GMT)
committer Dan Williams <dcbw@redhat.com>2006-06-27 16:03:06 (GMT)
commita0397b29dfe07a916fef3004dc6a8314220a7c03 (patch)
treeea63ff62de8e8ba5c8401b4293fc89fa3bbf3624 /sugar/p2p
parent5691d1e82856496cabbf11a2eb894b9c167d3b01 (diff)
Add some simple network test code for 2 machines
Diffstat (limited to 'sugar/p2p')
-rw-r--r--sugar/p2p/MostlyReliablePipe.py49
1 files changed, 47 insertions, 2 deletions
diff --git a/sugar/p2p/MostlyReliablePipe.py b/sugar/p2p/MostlyReliablePipe.py
index 5aee04c..5b503c2 100644
--- a/sugar/p2p/MostlyReliablePipe.py
+++ b/sugar/p2p/MostlyReliablePipe.py
@@ -1055,7 +1055,7 @@ class SHAUtilsTestCase(unittest.TestCase):
-def foobar():
+def unit_test():
suite = unittest.TestSuite()
SegmentBaseInitTestCase.addToSuite(suite)
DataSegmentTestCase.addToSuite(suite)
@@ -1073,7 +1073,7 @@ def got_data(addr, data, user_data=None):
fl.write(data)
fl.close()
-def main():
+def simple_test():
import sys
pipe = MostlyReliablePipe('', '224.0.0.222', 2293, got_data, sys.argv[2])
# pipe.set_drop_probability(4)
@@ -1096,6 +1096,51 @@ franker, more natural, as it were -- she really must exclude me from privileges
print 'Ctrl+C pressed, exiting...'
+
+def net_test_got_data(addr, data, user_data=None):
+ # Don't report data if we are a sender
+ if user_data:
+ return
+ print "%s (%s)" % (data, addr)
+
+idstamp = 0
+def transmit_data(pipe):
+ global idstamp
+ msg = "Message #%d" % idstamp
+ print "Sending '%s'" % msg
+ pipe.send(msg)
+ idstamp = idstamp + 1
+ return True
+
+def network_test():
+ import sys, os
+ send = False
+ if len(sys.argv) != 2:
+ print "Need one arg, either 'send' or 'recv'"
+ os._exit(1)
+ if sys.argv[1] == "send":
+ send = True
+ elif sys.argv[1] == "recv":
+ send = False
+ else:
+ print "Arg should be either 'send' or 'recv'"
+ os._exit(1)
+
+ pipe = MostlyReliablePipe('', '224.0.0.222', 2293, net_test_got_data, send)
+ pipe.start()
+ if send:
+ gobject.timeout_add(1000, transmit_data, pipe)
+ try:
+ gtk.main()
+ except KeyboardInterrupt:
+ print 'Ctrl+C pressed, exiting...'
+
+
+def main():
+# unit_test()
+# simple_test()
+ network_test()
+
if __name__ == "__main__":
main()