Search code examples
python-2.7python-3.xsocketssetsockopt

python 3 'MarkerServer' object has no attribute 'setsockopt'


I am having an old python 27 code that I am trying to port to python 35 and was having a doubt on the following part:

class MarkerServer(asyncore.dispatcher):

def __init__(self, queue, proto):

    asyncore.dispatcher.__init__(self)
    self.queue = queue
    if proto.lower() == 'tcp':
        logger.debug('Opening TCP socket.')
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
        self.setblocking(0)
        self.bind(('', PORT))
        self.listen(5)
    elif proto.lower() == 'udp':
        logger.debug('Opening UDP socket.')
        self.create_socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        self.setblocking(0)
        self.bind(('', PORT))
        handler = MarkerHandler(self, self.queue)
    else:

this is returning the following error:

    self.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    AttributeError: 'MarkerServer' object has no attribute 'setsockopt'

Solution

  • Thank you for the comment jasonharper. I realised there is also a deeper problem in the asyncore module of python 35. Not all methods seem to have been ported and were generating errors. Problem solved after modifying the module.