Improve complete with last exercice.

This commit is contained in:
Boris Baldassari 2024-02-01 09:33:41 +01:00
parent a1b31fea9d
commit 53e74fdd79
2 changed files with 6 additions and 6 deletions

View file

@ -30,14 +30,15 @@ def _parse_args():
return args
def answer():
def answer(addr):
"""
Returns an answer to the connection.
:return: A string.
"""
return "Gotcha.\n"
out = f"Hello {addr[0]}! You are using port {addr[1]}. Have a nice day!\n"
return out
def server(port: int=4444):
@ -54,7 +55,7 @@ def server(port: int=4444):
while True:
c, addr = s.accept()
print('Got connection from', addr)
c.send(answer().encode('utf-8'))
c.send(answer(addr).encode('utf-8'))
c.close()
if __name__ == '__main__':

View file

@ -34,8 +34,7 @@ def _parse_args():
print(parser.print_help())
sys.exit(1)
else:
print("Got port option set to:", args.port)
print("Got port option set to:", args.port)
return args