Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

At what level(s) was this OD intervention scoped?

Answered: 1 week ago