def open(self):
        """open serial port, start network server and publish service"""
        self.buffer_net2ser = bytearray()
        self.buffer_ser2net = bytearray()

        # open serial port
        try:
            self.serial.rts = False
            self.serial.open()
        except Exception as msg:
            self.handle_serial_error(msg)

        self.serial_settings_backup = self.serial.get_settings()

        # start the socket server
        # XXX add IPv6 support: use getaddrinfo for socket options, bind to multiple sockets?
        #       info_list = socket.getaddrinfo(None, port, 0, socket.SOCK_STREAM, 0, socket.AI_PASSIVE)
        self.server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.server_socket.setsockopt(
            socket.SOL_SOCKET,
            socket.SO_REUSEADDR,
            self.server_socket.getsockopt(
                socket.SOL_SOCKET,
                socket.SO_REUSEADDR
            ) | 1
        )
        self.server_socket.setblocking(0)
        try:
            self.server_socket.bind(('', self.network_port))
            self.server_socket.listen(1)
        except socket.error as msg:
            self.handle_server_error()
            #~ raise
        if self.log is not None:
            self.log.info("%s: Waiting for connection on %s..." % (self.device, self.network_port))

        # zeroconfig
        self.publish()

        # now we are ready
        self.alive = True
dataset/ETHPy150Open pyserial/pyserial/examples/port_publisher.py/Forwarder.open/original