def clientConnection(netsettings, report = None, scan = True, timeout = 5): address = netsettings.server_address port = netsettings.server_port use_ssl = netsettings.use_ssl if address== "[default]": # calling operator from python is fucked, scene isn't in context # if bpy: # bpy.ops.render.netclientscan() # else: if not scan: return None
address, port = clientScan() if address == "": return None conn = None try: HTTPConnection = http.client.HTTPSConnection if use_ssl else http.client.HTTPConnection if platform.system() == "Darwin": with ConnectionContext(timeout): conn = HTTPConnection(address, port) else: conn = HTTPConnection(address, port, timeout = timeout)
if conn: if clientVerifyVersion(conn, timeout): return conn else: conn.close() reporting(report, "Incorrect master version", ValueError) except BaseException as err: if report: report({'ERROR'}, str(err)) return None else: print(err) return None
def clientVerifyVersion(conn, timeout): with ConnectionContext(timeout): conn.request("GET", "/version") response = conn.getresponse()
if response.status != http.client.OK: conn.close() return False
server_version = response.read()
if server_version != VERSION: print("Incorrect server version!") print("expected", str(VERSION, encoding='utf8'), "received", str(server_version, encoding='utf8')) return False
return True |