Source code for odoo_xmlrpc_twisted.functions.test_twisted_connection
"""Tests the connection to the Twisted Server."""importsocketimportos.pathimportconfigparser# get the location of the Parameter File "parameter_global.ini"pathname=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# Go up to repo rootconfig_path=os.path.join(pathname,'config')filename='parameter_global.ini'fullpath=os.path.join(config_path,filename)config=configparser.ConfigParser()config.read(fullpath)custom_host=config['get_settings_twisted']['host']custom_port=int(config['get_settings_twisted']['port'])
[docs]deftest_twisted_connection():""" Tests if the connection to the Twisted Server works. The function gives back the result of the testing. """try:# Crate a socket objectsock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)# set a timeout for the connectionsock.settimeout(1)# timeout is 1 second# try to get a connection to the serversock.connect((custom_host,custom_port))sock.close()# close the connectionresult='True'exceptException:result='False'return(result)