Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server configuration #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions server.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Empty file added server_configuration.json
Empty file.