예제 #1
0
 def __init__(self, channeltype, band):
     ''' Get encoder and pass it to NetworkManager '''
     self._channeltype = channeltype
     self._band = band
     encoder = MessageEncoderFactory.create(channeltype, band)
     self._encoder = encoder
     if not encoder:
         raise Error('Such encoder does not exist')
     self._netmanager = NetworkManager(encoder)        
     self._buffer = ('',  None)        
예제 #2
0
 def bind(self, addr):
     ''' 
         Binds socket to given host and port. Fails if same port is already bou-
         nd or if privileges are insufficient. NFQueue loop is run in child pro-
         cces. addr is a tuple (host, port).    Localhost is denoted by empty 
         string (' ').
     '''
     if len(addr) < 2:
         raise Error('Invalid argument')
     try:
         if self._encoder.initpackets():
             self._encoder = MessageEncoderFactory.create(self._channeltype, 
                                                          self._band )
         self._netmanager.bind(addr)
     except gaierror,  e:
         raise Error('Given hostname or addres is not valid: ' + str(e))