Network Programming 1
Network Programming 1
The entire activity can be wrapped in a free-standing function, print_machine_info(), which uses the built-in socket
class methods
Net Programming RF Sockets, IPv4, and Simple Client/Server Programming
Printing your machine's name and IPv4 address
Every module in Python has a special attribute called __name__. The value of __name__ attribute is set to '__main__'
when module run as main program. Otherwise, the value of __name__ is set to contain the name of the module.
Net Programming RF Sockets, IPv4, and Simple Client/Server Programming
As you can see, we wrapped the main function call inside a try
except block. This means that, if some error occurs during the
execution of this function, this error will be dealt with by this
try-except block.
Net Programming RF Sockets, IPv4, and Simple Client/Server Programming
port= socket.getservbyname("http")
print (port)
Net Programming RF Sockets, IPv4, and Simple Client/Server Programming