For context I am making a game, in the game there is a multiplayer feature, when I click on the multiplayer button is works as it imports a file client.py
, after the first game ends, I need to call client.py
once again as there a line client.connect(ADDR)
in the global scope. But python refuses to import the file again, I need the client to connect again as it disconnects after the first game.... Any ideas?
client.py
:
import socket
print("HIII") #This is was there for testing
HEADER = 6400
PORT = 5050
FORMAT = 'utf-8'
DISCONNECT_MESSAGE = "!DISCONNECT"
SERVER = "<Ipv4 address here>"
ADDR = (SERVER, PORT)
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(ADDR)
def send(msg, send=True):
if send:
message = msg.encode(FORMAT)
client.send(message)
msgFromServer = client.recv(HEADER).decode(FORMAT)
return msgFromServer