Beispiel #1
0
    def __init__(self, ip, port) :
        self._cb = None
        self.instance = pynorm.Instance()
        
        self.session = self.instance.createSession(ip, port)
        self.session.setRxPortReuse(True, False)
        self.session.startReceiver(1024*1024)
        self.session.startSender(randint(0, 1000), 1024**2, 1400, 64, 16)
        self.stream = self.session.streamOpen(1024*1024)

        self.manager = Manager(self.instance)
        self.manager.register(pynorm.NORM_RX_OBJECT_UPDATED, self._on_rx_object_updated)
        self.manager.start()
Beispiel #2
0
class NormMcSocket :
    def __init__(self, ip, port) :
        self._cb = None
        self.instance = pynorm.Instance()
        
        self.session = self.instance.createSession(ip, port)
        self.session.setRxPortReuse(True, False)
        self.session.startReceiver(1024*1024)
        self.session.startSender(randint(0, 1000), 1024**2, 1400, 64, 16)
        self.stream = self.session.streamOpen(1024*1024)

        self.manager = Manager(self.instance)
        self.manager.register(pynorm.NORM_RX_OBJECT_UPDATED, self._on_rx_object_updated)
        self.manager.start()

    def _on_rx_object_updated(self, event) :
        print 'recv:', event.object

    def send(self, data) :
        self.stream.streamWrite(data)
        self.stream.streamFlush(True)

    def set_recv_cb(self, fn) :
        self._recv_cb = fn
def main(argv):
    (opts, args) = get_option_parser().parse_args(argv)

    if len(args) != 2:
        print get_option_parser().get_usage()
        return 1

    instance = pynorm.Instance()
    session = instance.createSession(opts.address, opts.port)

    if opts.iface:
        session.setMulticastInterface(opts.iface)

    session.startReceiver(1024*1024)
    session.startSender(randint(0, 1000), 1024**2, 1400, 64, 16)
    stream = session.streamOpen(1024*1024)

    gui = Gui(stream, args[1])

    manager = Manager(instance)
    manager.register(pynorm.NORM_RX_OBJECT_UPDATED,
            lambda e: gui.showText(e.object.streamRead(1024)[1]))
#    manager.register(pynorm.NORM_RX_OBJECT_INFO,
#            lambda e: gui.showText('%s joined the chat' % e.object.info))
    manager.start()

    try:
        curses.wrapper(gui)
    except KeyboardInterrupt:
        pass

    print 'Exiting...'
    stream.streamClose(True)
    instance.stop()
    manager.join()
    return 0
def main(argv):
    (opts, args) = get_option_parser().parse_args(argv)

    if len(args) != 2:
        print get_option_parser().get_usage()
        return 1

    path = os.path.abspath(args[1])

    instance = pynorm.Instance()
    instance.setCacheDirectory(path)

    try:
        instance.openDebugPipe(opts.pipe)
    except pynorm.NormError:
        print 'Could not connect to pipe, disabling...'
    pynorm.setDebugLevel(opts.debug)

    manager = Manager(instance)
    manager.register(pynorm.NORM_RX_OBJECT_INFO, newObject, path)
#    manager.register(pynorm.NORM_RX_OBJECT_UPDATED, updatedObject)
    manager.register(pynorm.NORM_RX_OBJECT_COMPLETED, complete)
    manager.register(pynorm.NORM_RX_OBJECT_ABORTED, abort)
    manager.start()

    session = instance.createSession(opts.address, opts.port)
    if opts.iface:
        session.setMulticastInterface(opts.iface)
    session.startReceiver(1024*1024)

    print 'Starting listener on %s:%i' % (opts.address, opts.port)
    try:
        while True:
            manager.join(2)
    except KeyboardInterrupt:
        pass
    print 'Exiting...'
    instance.stop()
    manager.join()
    return 0