Clean up student version, improve step 1.

This commit is contained in:
Boris Baldassari 2024-02-01 09:08:31 +01:00
parent f3f5c2dd72
commit a1b31fea9d
2 changed files with 11 additions and 9 deletions

View file

@ -33,6 +33,9 @@ def _parse_args():
print("Please provide a port for the connection.")
print(parser.print_help())
sys.exit(1)
else:
print("Got port option set to:", args.port)
return args
@ -47,7 +50,7 @@ def answer():
return "Gotcha.\n"
def server(port: int=4444):
def server(port: int):
"""
Opens a socket on a given port and listens to incoming
requests. When a request comes in, accepts the connection,

View file

@ -11,7 +11,7 @@
"""
This module plays with sockets.
More info.
Fill in more info, explaining what this module does and how to use it.
"""
@ -23,10 +23,8 @@ def _parse_args():
"""
Parses arguments from command line.
"""
parser = argparse.ArgumentParser(description="Utilities to use network sockets.")
parser.add_argument('-p', '--port',
help='Port number to open')
args = parser.parse_args()
#parser = ...
return args
@ -40,7 +38,7 @@ def answer():
return "Gotcha.\n"
def server(port: int=4444):
def server(port: int):
"""
Opens a socket on a given port and listens to incoming
requests. When a request comes in, accepts the connection,
@ -48,14 +46,15 @@ def server(port: int=4444):
:param port: Port number to listen on.
"""
print("Starting server..")
if __name__ == '__main__':
# Parse command-line arguments
args = _parse_args()
# Start our server
server(int(args.port))
#server(...)