Question: Write a python method named connectTcp that will create TCP IPv4 socket ( AF_INET , SOCK_STREAM ), connect to the specified host/port, closes the connection,
Write a python method named connectTcp that will create TCP IPv4 socket ( AF_INET , SOCK_STREAM ), connect to the specified host/port, closes the connection, and returns True if the connection was established correctly.
The input parameters are a variable named host (type string) and a variable named port (type integer)
The return value is type bool. It is True if the TCP connection is successfully established, and if not False
You can test this method with any Internet service, for example:
a = Assignment("John")
value = a.connectTcp("www.google.com", 80)
if value:
print("Connection correctly established")
else:
print("error")
If you are trying to connect and a connection cannot be established, a default exception will be thrown. A case needs to be constructed to return False.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
