コード例 #1
0
    def __init__(self, ip, port, myport=None, protocol='bcixml'):
        """
        Initialize BciNetwork instance.

        :param ip: IP Address. If emtpy, assume localhost
        :type ip: str
        :param port: Port Number
        :type port: integer

        """
        self.logger = logging.getLogger("BciNetwork-%s:%s" % (str(ip), str(port)))
        self.logger.debug("BciNetwork initialized.")

        if ip == "":
            self.logger.debug("Got empty IP, assuming localhost.")
            ip = LOCALHOST

        self.addr = (ip, port)
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        self.SEND_ONLY = True
        if myport != None:
            self.SEND_ONLY = False
            self.srvsocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.srvsocket.bind(('', myport))

        if protocol == 'json':
            self.xmlencoder = bcixml.JsonEncoder()
            self.xmldecoder = bcixml.JsonDecoder()
        else:
            # tobi and bcixml share the same encoder
            self.xmlencoder = bcixml.XmlEncoder()
            self.xmldecoder = bcixml.XmlDecoder()
コード例 #2
0
 def __init__(self, fc, protocol):
     asyncore.dispatcher.__init__(self)
     self.fc = fc
     if protocol == 'tobixml':
         self.decoder = bcixml.TobiXmlDecoder()
     else:
         self.decoder = bcixml.XmlDecoder()
     self.encoder = bcixml.XmlEncoder()
     self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)
     self.bind((bcinetwork.LOCALHOST, bcinetwork.FC_PORT))
コード例 #3
0
    def __init__(self, fc, protocol):
        asyncore.dispatcher.__init__(self)
        self.fc = fc
        if protocol == 'json':
            self.decoder = bcixml.JsonDecoder()
            self.encoder = bcixml.JsonEncoder()
        elif protocol == 'tobixml':
            # tobi and bcixml share the same encoder
            self.decoder = bcixml.TobiXmlDecoder()
            self.encoder = bcixml.XmlEncoder()
        else:
            self.decoder = bcixml.XmlDecoder()
            self.encoder = bcixml.XmlEncoder()
        self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)

        # and THIS ... is why it only accepts stuff from Localhost.
        # and why self.bind? So the asyncore.dispatcher is like-a-socket itself?

        # UDP server shouldn't care which IP is used to let others connect to it.
        # since the name of the computer which the server is running on, might be
        # any given IP address. As long as the port seems to be OK, accept things.
        # self.bind((bcinetwork.LOCALHOST, bcinetwork.FC_PORT))
        self.bind(('', bcinetwork.FC_PORT))
コード例 #4
0
 def setUp(self):
     self.encoder = bcixml.XmlEncoder()
     self.decoder = bcixml.XmlDecoder()