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))
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))