I am currently creating a multiplayer game and files named client.py and server.py. The server is launching properly, multiple clients can connect, everything is working fine.

What I want now is the server to restart once the game is finished instead of closing and restarting manually. I tried several methods with the modules sys and os but all of them thrown with an error. I suppose I need to close the server then launch it again. I use the module UrsinaNetworking to make it easier.

I wrote the following functions in server.py :

def GenerateServer():
    print("Hello from the server !")
    global Server
    Server = UrsinaNetworkingServer("localhost", 25565)
    global Easy
    Easy = EasyUrsinaNetworkingServer(Server)
@Server.event
def EndGame(Client, when):
    Server.close()
    GenerateServer()

I needed to add the Server.close() in the module file ursinanetworking.py in the class UrsinaNetworkingServer():

    def close(self):
        self.server.shutdown(socket.SHUT_RDWR)
        self.server.close() # Built-in Socket API function
        print ("closed")

And that throws into the following an error.

Python Socket Error : A request to send or receive data was disallowed because the socket is not connected and no address was supplied

Am I missing the point or something? Let me know if you need some more details.

0

There are 0 best solutions below