From 768801bd7ba322c3cc43a64ac0dc5ff290f2b31d Mon Sep 17 00:00:00 2001 From: EduardoJTR Date: Fri, 23 Sep 2022 13:52:50 -0300 Subject: [PATCH 1/2] Server configuration --- server.py | 26 ++++++++++++++++++++++---- server_configuration.json | 4 ++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 server_configuration.json diff --git a/server.py b/server.py index 0d88c6d..ddb4d9f 100644 --- a/server.py +++ b/server.py @@ -1,9 +1,27 @@ import threading import socket -# Now this Host is the IP address of the Server, over which it is running. -# I've user my localhost. -host = "192.168.2.104" -port = 5555 # Choose any random port which is not so common (like 80) +import json +import os + +# Menu loop, only break when user want to start the server +while True: + os.system('cls||clear') + option = input("(1)Start server\n(2)Configure ip/port of the server\n") + if option == '1': + break + elif option == '2': + os.system('cls||clear') + server_ip = input("Enter the ip of the server:") + server_port = int(input("Enter the port number of the server:")) + server_config = {"ip": server_ip, "port": server_port} + with open('server_configuration.json', 'w') as f: + json.dump(server_config, f, indent=4) + +os.system('cls||clear') +with open('server_configuration.json', 'r') as f: + server_data = json.load(f) + host = server_data["ip"] + port = server_data["port"] server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Bind the server to IP Address diff --git a/server_configuration.json b/server_configuration.json new file mode 100644 index 0000000..cd2119a --- /dev/null +++ b/server_configuration.json @@ -0,0 +1,4 @@ +{ + "ip": "192.168.2.104", + "port": 5566 +} \ No newline at end of file From f18cc75a7b80a8561e2a25ad98fa4bb2e5b138b3 Mon Sep 17 00:00:00 2001 From: EduardoJTR Date: Fri, 23 Sep 2022 13:55:53 -0300 Subject: [PATCH 2/2] Server info storage --- server_configuration.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/server_configuration.json b/server_configuration.json index cd2119a..e69de29 100644 --- a/server_configuration.json +++ b/server_configuration.json @@ -1,4 +0,0 @@ -{ - "ip": "192.168.2.104", - "port": 5566 -} \ No newline at end of file