Exemple #1
0
 def __init__(self,
              name='',
              version=raeting.VERSION,
              store=None,
              device=None,
              did=None,
              ha=("", raeting.RAET_PORT),
              rxMsgs = None,
              txMsgs = None,
              udpRxes = None,
              udpTxes = None,
              ):
     '''
     Setup StackUdp instance
     '''
     if not name:
         name = "stack{0}".format(StackUdp.Count)
         StackUdp.Count += 1
     self.name = name
     self.version = version
     self.store = store or storing.Store(stamp=0.0)
     self.devices = odict() # remote devices attached to this stack by did
     self.dids = odict() # reverse lookup did by device.name
      # local device for this stack
     self.device = device or devicing.LocalDevice(stack=self, did=did, ha=ha)
     self.transactions = odict() #transactions
     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
     #(msg, ddid) ddid=0 is broadcast
     self.udpRxes = udpRxes if udpRxes is not None else deque() # udp packets received
     self.udpTxes = udpTxes if udpTxes is not None else deque() # udp packet to transmit
     self.serverUdp = aiding.SocketUdpNb(ha=self.device.ha)
     self.serverUdp.reopen()  # open socket
     self.device.ha = self.serverUdp.ha  # update device host address after open
Exemple #2
0
 def serverFromLocal(self):
     '''
     Create local listening server for stack
     '''
     server = aiding.SocketUdpNb(ha=self.ha,
                                 bufsize=raeting.UDP_MAX_PACKET_SIZE *
                                 self.bufcnt)
     return server
Exemple #3
0
 def postinitio(self, connection, address, **kwa):
     '''
     Set up server to transmit and recive on address
     '''
     connection.value = aiding.SocketUdpNb(host=address.data.host,
                                           port=address.data.port)
     connection.value.reopen()  # create socket connection
     host, port = connection.value.ha
     address.update(host=host, port=port, ha=(host, port))
     return None
Exemple #4
0
    def __init__(self,
                 name='',
                 main=False,
                 version=raeting.VERSION,
                 store=None,
                 estate=None,
                 eid=None,
                 ha=("", raeting.RAET_PORT),
                 rxMsgs=None,
                 txMsgs=None,
                 udpRxes=None,
                 udpTxes=None,
                 road=None,
                 safe=None,
                 auto=None,
                 dirpath=None,
                 ):
        '''
        Setup StackUdp instance
        '''
        if not name:
            name = "stackUdp{0}".format(StackUdp.Count)
            StackUdp.Count += 1
        self.name = name
        self.version = version
        self.store = store or storing.Store(stamp=0.0)
        self.estates = odict() # remote estates attached to this stack by eid
        self.eids = odict() # reverse lookup eid by estate.name
        self.transactions = odict() #transactions
        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.udpRxes = udpRxes if udpRxes is not None else deque() # udp packets received
        self.udpTxes = udpTxes if udpTxes is not None else deque() # udp packet to transmit

        self.road = road or keeping.RoadKeep(dirpath=dirpath,
                                             stackname=self.name)
        self.safe = safe or keeping.SafeKeep(dirpath=dirpath,
                                             stackname=self.name,
                                             auto=auto)
        kept = self.loadLocal() # local estate from saved data
        # local estate for this stack
        self.estate = kept or estate or estating.LocalEstate(stack=self,
                                                             eid=eid,
                                                             main=main,
                                                             ha=ha)
        self.estate.stack = self
        self.serverUdp = aiding.SocketUdpNb(ha=self.estate.ha, bufsize=raeting.MAX_MESSAGE_SIZE)
        self.serverUdp.reopen()  # open socket
        self.estate.ha = self.serverUdp.ha  # update estate host address after open
        self.dumpLocal() # save local estate data

        kepts = self.loadAllRemote() # remote estates from saved data
        for kept in kepts:
            self.addRemoteEstate(kept)
        self.dumpAllRemote() # save remote estate data
Exemple #5
0
def TestSocketUdpNB():
    """Class SocketUdpNb self test """
    try:
        print("Testing SocketUdpNb")
        serverA = aiding.SocketUdpNb(port=6101)
        serverA.reopen()
        serverB = aiding.SocketUdpNb(port=6102)
        serverB.reopen()

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

    finally:
        serverA.close()
        serverB.close()
Exemple #6
0
    def __init__(self,
                 name='',
                 main=None,
                 keep=None,
                 dirpath=None,
                 local=None,
                 eid=None,
                 ha=("", raeting.RAET_PORT),
                 bufcnt=2,
                 safe=None,
                 auto=None,
                 **kwa):
        '''
        Setup StackUdp instance
        '''
        if not name:
            name = "roadstack{0}".format(RoadStack.Count)
            RoadStack.Count += 1

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

        if not safe:
            safe = keeping.SafeKeep(dirpath=dirpath, stackname=name, auto=auto)
        else:
            if auto is not None:
                safe.auto = True if auto else False
        self.safe = safe

        if not local:
            self.remotes = odict()
            local = estating.LocalEstate(stack=self, eid=eid, main=main, ha=ha)
        else:
            if main is not None:
                local.main = True if main else False

        server = aiding.SocketUdpNb(ha=local.ha,
                                    bufsize=raeting.UDP_MAX_PACKET_SIZE *
                                    bufcnt)

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

        self.transactions = odict()  #transactions

        self.dumpLocal()  # save local data
        self.dumpRemotes()  # save remote data
Exemple #7
0
 def __init__(
     self,
     name='',
     version=raeting.VERSION,
     store=None,
     estate=None,
     eid=None,
     ha=("", raeting.RAET_PORT),
     rxMsgs=None,
     txMsgs=None,
     udpRxes=None,
     udpTxes=None,
     road=None,
     safe=None,
 ):
     '''
     Setup StackUdp instance
     '''
     if not name:
         name = "stackUdp{0}".format(StackUdp.Count)
         StackUdp.Count += 1
     self.name = name
     self.version = version
     self.store = store or storing.Store(stamp=0.0)
     self.estates = odict()  # remote estates attached to this stack by eid
     self.eids = odict()  # reverse lookup eid by estate.name
     # local estate for this stack
     self.estate = estate or estating.LocalEstate(
         stack=self, eid=eid, ha=ha)
     self.transactions = odict()  #transactions
     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
     #(msg, deid) deid=0 is broadcast
     self.udpRxes = udpRxes if udpRxes is not None else deque(
     )  # udp packets received
     self.udpTxes = udpTxes if udpTxes is not None else deque(
     )  # udp packet to transmit
     self.road = road or keeping.RoadKeep()
     self.safe = safe or keeping.SafeKeep()
     self.serverUdp = aiding.SocketUdpNb(ha=self.estate.ha,
                                         bufsize=raeting.MAX_MESSAGE_SIZE)
     self.serverUdp.reopen()  # open socket
     self.estate.ha = self.serverUdp.ha  # update estate host address after open