def start(self):
        """Start the server.

        Do nothing if server is already running.
        This function will block if no_block is not set to True.
        """
        if not self.is_run:
            # set class attribute
            ThreadingTCPServer.address_family = socket.AF_INET6 if self.ipv6 else socket.AF_INET
            ThreadingTCPServer.daemon_threads = True
            # init server
            self._service = ThreadingTCPServer((self.host, self.port), self.ModbusService, bind_and_activate=False)
            # set socket options
            self._service.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self._service.socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
            # TODO test no_delay with bench
            self._service.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
            # bind and activate
            self._service.server_bind()
            self._service.server_activate()
            # serve request
            if self.no_block:
                self._serve_th = Thread(target=self._serve)
                self._serve_th.daemon = True
                self._serve_th.start()
            else:
                self._serve()
def start ( self ) : if not self . is_run : ThreadingTCPServer . address_family = socket . AF_INET6 if self . ipv6 else socket . AF_INET ThreadingTCPServer . daemon_threads = True self . _service = ThreadingTCPServer ( ( self . host , self . port ) , self . ModbusService , bind_and_activate = False ) self . _service . socket . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) self . _service . socket . setsockopt ( socket . SOL_SOCKET , socket . SO_KEEPALIVE , 1 ) self . _service . socket . setsockopt ( socket . IPPROTO_TCP , socket . TCP_NODELAY , 1 ) self . _service . server_bind ( ) self . _service . server_activate ( ) if self . no_block : self . _serve_th = Thread ( target = self . _serve ) self . _serve_th . daemon = True self . _serve_th . start ( ) else : self . _serve ( )
Start the server.

        Do nothing if server is already running.
        This function will block if no_block is not set to True.