Example #1
0
def TestSocketUxdNB():
    """Class SocketUxdNb self test """
    console.reinit(verbosity=console.Wordage.verbose)
    try:
        print("Testing SocketUxdNb")
        serverA = aiding.SocketUxdNb(ha='/tmp/local/uxdA', umask=0x077)
        serverA.reopen()
        serverB = aiding.SocketUxdNb(ha='/tmp/local/uxdB', umask=0x077)
        serverB.reopen()
        serverC = aiding.SocketUxdNb(ha='/tmp/local/uxdC', umask=0x077)
        serverC.reopen()

        serverA.send("A sends to B", serverB.ha)
        print(serverB.receive())
        serverA.send("A sends to C", serverC.ha)
        print(serverC.receive())
        serverA.send("A sends to A", serverA.ha)
        print(serverA.receive())
        serverB.send("B sends to A", serverA.ha)
        print(serverA.receive())
        serverC.send("C sends to A", serverA.ha)
        print(serverA.receive())
        serverB.send("B sends to B", serverB.ha)
        print(serverB.receive())
        serverC.send("C sends to C", serverC.ha)
        print(serverC.receive())

        serverA.send("A sends to B again", serverB.ha)
        print(serverB.receive())
        serverA.send("A sends to C again", serverC.ha)
        print(serverC.receive())
        serverA.send("A sends to A again", serverA.ha)
        print(serverA.receive())
        serverB.send("B sends to A again", serverA.ha)
        print(serverA.receive())
        serverC.send("C sends to A again", serverA.ha)
        print(serverA.receive())
        serverB.send("B sends to B again", serverB.ha)
        print(serverB.receive())
        serverC.send("C sends to C again", serverC.ha)
        print(serverC.receive())

        print(serverA.receive())
        print(serverB.receive())
        print(serverC.receive())

    finally:
        serverA.close()
        serverB.close()
        serverC.close()
Example #2
0
 def serverFromLocal(self):
     '''
     Create local listening server for stack
     '''
     server = aiding.SocketUxdNb(ha=self.ha,
                                 bufsize=raeting.UXD_MAX_PACKET_SIZE *
                                 self.bufcnt)
     return server
Example #3
0
    def serverFromLocal(self):
        '''
        Create server from local data
        '''
        if not self.local:
            return None

        server = aiding.SocketUxdNb(ha=self.local.ha,
                                    bufsize=raeting.UXD_MAX_PACKET_SIZE *
                                    self.bufcnt)
        return server
Example #4
0
    def serverFromLocal(self):
        '''
        Create local listening server for stack
        '''

        if not sys.platform == 'win32':
            server = aiding.SocketUxdNb(ha=self.ha,
                                        bufsize=raeting.UXD_MAX_PACKET_SIZE *
                                        self.bufcnt)
        else:
            server = aiding.WinMailslotNb(ha=self.ha,
                                          bufsize=raeting.UXD_MAX_PACKET_SIZE *
                                          self.bufcnt)
        return server
Example #5
0
 def __init__(
     self,
     name='',
     version=raeting.VERSION,
     store=None,
     lanename='lane',
     yard=None,
     yid=None,
     yardname='',
     ha='',
     rxMsgs=None,
     txMsgs=None,
     uxdRxes=None,
     uxdTxes=None,
     lane=None,
     accept=None,
     dirpath=None,
 ):
     '''
     Setup StackUxd instance
     '''
     if not name:
         name = "stackUxd{0}".format(StackUxd.Count)
         StackUxd.Count += 1
     self.name = name
     self.version = version
     self.store = store or storing.Store(stamp=0.0)
     self.yards = odict()  # remote uxd yards attached to this stack by name
     self.names = odict()  # remote uxd yard names  by ha
     self.yard = yard or yarding.Yard(stack=self,
                                      name=yardname,
                                      yid=yid,
                                      ha=ha,
                                      prefix=lanename,
                                      dirpath=dirpath)
     self.rxMsgs = rxMsgs if rxMsgs is not None else deque(
     )  # messages received
     self.txMsgs = txMsgs if txMsgs is not None else deque(
     )  # messages to transmit
     self.uxdRxes = uxdRxes if uxdRxes is not None else deque(
     )  # uxd packets received
     self.uxdTxes = uxdTxes if uxdTxes is not None else deque(
     )  # uxd packets to transmit
     self.lane = lane  # or keeping.LaneKeep()
     self.accept = self.Accept if accept is None else accept  #accept uxd msg if not in lane
     self.serverUxd = aiding.SocketUxdNb(ha=self.yard.ha,
                                         bufsize=raeting.MAX_MESSAGE_SIZE)
     self.serverUxd.reopen()  # open socket
     self.yard.ha = self.serverUxd.ha  # update estate host address after open
Example #6
0
    def __init__(self,
                 name='',
                 main=False,
                 keep=None,
                 dirpath='',
                 local=None,
                 lanename='lane',
                 yid=None,
                 yardname='',
                 sockdirpath='',
                 ha='',
                 bufcnt=10,
                 accept=None,
                 **kwa):
        '''
        Setup StackUxd instance
        '''
        if not name:
            name = "lanestack{0}".format(LaneStack.Count)
            LaneStack.Count += 1

        if not keep:
            keep = keeping.LaneKeep(dirpath=dirpath, stackname=name)

        if not local:
            self.remotes = odict()
            local = yarding.LocalYard(stack=self,
                                      yid=yid,
                                      name=yardname,
                                      main=main,
                                      ha=ha,
                                      dirpath=sockdirpath,
                                      lanename=lanename)

        server = aiding.SocketUxdNb(ha=local.ha,
                                    bufsize=raeting.UXD_MAX_PACKET_SIZE *
                                    bufcnt)

        super(LaneStack, self).__init__(name=name,
                                        keep=keep,
                                        dirpath=dirpath,
                                        local=local,
                                        server=server,
                                        **kwa)

        self.books = odict()
        self.accept = self.Accept if accept is None else accept  #accept uxd msg if not in lane