Verteiltesystheme/Code/Main.py

49 lines
927 B
Python

import sys
import threading
from Code.Communication.Direction import Direction
from Code.Communication.Member import Member
from Code.Communication.Neighbours import Neighbours
from Code.Communication.Server import Server
from Code.UI.PlayingField import run_game
if __name__ == "__main__":
"""
Getting the args
- own port
Optional: A neighbour:
- ip
- port
- direction
"""
args = sys.argv
print(args)
if len(args) >= 2:
own_port =int(args[1])
else:
print("using default port 8080")
own_port = 8080
if len(args) >= 4:
n_ip = args[2]
n_port = int(args[3])
if len(args) > 4:
n_direction = args[4]
neighbours = Neighbours(own_process=Member("0.0.0.0", own_port))
server = Server(neighbours)
neighbours.connect(Direction[n_direction], n_ip, n_port)
serverThread = threading.Thread(target=server.start)
serverThread.start()
run_game()
print("finished game")
server.stop_server()