def main(): global debug if not len(sys.argv[1:]): usage() # read the commandline options try: opts, args = getopt.getopt(sys.argv[1:],"d") for o,a in opts: if o in ("-d"): debug = True else: assert False,"Unhandled Option" if len(args) == 1: port = int(args[0]) else: usage() rsock = rudp.rudp_socket(port) # Catch errors in argument parsing except (getopt.GetoptError, socket.error, SyntaxError) as err: print str(err) usage() # Register receiver and event handler callback functions rudp.rudp_recvfrom_handler(rsock, recvfromhandler) rudp.rudp_event_handler(rsock, eventhandler) if debug: print "RUDP receiver waiting on port %d" % (port) # Hand over control to event manager event.eventloop()
def send_file(filename): """Initiate sending of a file with RUDP. Create a RUDP socket for sending. Send the file name to the VS receiver. Register a handler for input event, which will take care of sending file data""" f = open(filename, "rb") rsock = rudp.rudp_socket(0) rudp.rudp_event_handler(rsock, eventhandler) rudp.rudp_recvfrom_handler(rsock, recvfrom_handler) # Strip of any leading path name and create start packet vsm = vsftp.vsftp() vsm.vs_type = vsftp.VS_TYPE_BEGIN vsm.vs_filename = os.path.basename(filename) buf = vsm.pack() for p in peers: (address, port, flow, scope) = p if debug: print "vs_send: send BEGIN \"%s\" (%d bytes) to %s:%s" % (filename, len(buf), address, port) rudp.rudp_sendto(rsock, buf, p) # Launch event driven filesender to send file content event.event_fd(f, filesender, rsock, "filesender")
def main(): global debug if not len(sys.argv[1:]): usage() # read the commandline options try: opts, args = getopt.getopt(sys.argv[1:], "d") for o, a in opts: if o in ("-d"): debug = True else: assert False, "Unhandled Option" if len(args) == 1: port = int(args[0]) else: usage() rsock = rudp.rudp_socket(port) # Catch errors in argument parsing except (getopt.GetoptError, socket.error, SyntaxError) as err: print str(err) usage() # Register receiver and event handler callback functions rudp.rudp_recvfrom_handler(rsock, recvfromhandler) rudp.rudp_event_handler(rsock, eventhandler) if debug: print "RUDP receiver waiting on port %d" % (port) # Hand over control to event manager event.eventloop()