Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Trying to create a TCP client using Python to test the backend connectivity of any host.

Compilation of script py://connect.py failed.
python script:

import socket

def establish_tcp_connection(host, port):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
print(f"TCP connection established with {host}:{port}")
sock.close()
except socket.error as e:
print(f"Error: {e}")

# Example usage
var host= flow.getVariable('targethost');
var port= flow.getVariable('targetport');

establish_tcp_connection(host, port)

the host and port values can be taken from the request. I am getting a compilation error while trying to deploy the proxy with the above script.


Will this work or is there a different way i can approach this.

0 3 737
3 REPLIES 3