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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started