Source code for odoo_xmlrpc_twisted.functions.test_twisted_connection

"""
Tests the connection to the Twisted Server.
"""

import socket
import os.path
import configparser


# 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 root
config_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] def test_twisted_connection(): """ Tests if the connection to the Twisted Server works. The function gives back the result of the testing. """ try: # Crate a socket object sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # set a timeout for the connection sock.settimeout(1) # timeout is 1 second # try to get a connection to the server sock.connect((custom_host, custom_port)) sock.close() # close the connection result = 'True' except Exception: result = 'False' return(result)