Menu

(Solved) : Write Python Method Named Connecttcp Create Tcp Ipv4 Socket Afinet Sockstream Connect Spec Q44047240 . . .

Write a python method named connectTcp that will create TCP IPv4socket ( AF_INET , SOCK_STREAM ), connect to the specifiedhost/port, closes the connection, and returns True if theconnection 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, forexample:

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 youtrying to connect and connection cannot be established. You willneed to handle this case to return False as required by thistask.

Expert Answer


Answer to Write a python method named connectTcp that will create TCP IPv4 socket ( AF_INET , SOCK_STREAM ), connect to the specif…

OR