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.

Input parameters: a. variable named host : type str

b. variable named port : type int

Return value

a. type bool : True if TCP connection successfully established, otherwise False

You can test this method with any Internet service, for example:

a = Assignment2("Jason") retval = a.connectTcp("www.google.com", 80)

if retval:

print("Connection established correctly")

else:

print("Some error")

Note that Python 3 by default will throw an exception if you trying to connect and connection cannot be established. You will need to handle this case to return False as required by this task.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!