From a0397b29dfe07a916fef3004dc6a8314220a7c03 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Tue, 27 Jun 2006 16:03:06 +0000 Subject: Add some simple network test code for 2 machines --- (limited to 'sugar') 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() -- cgit v0.9.1