Reputation: 19
I am making a simple game with multiplayer mode in it. I need to somehow send data between one player and other. I can't find a way to transfer data between two clients. Is there a way to forward them through the server?
I'm using the socketserver
library to accept connections. Here is the way I handle connections.
def handle(self):
data = self.request.recv(BUFFSIZE).decode("utf-8")
print("Received connection")
print(data)
Upvotes: 0
Views: 317
Reputation: 40884
From the 90s playbook: one of the clients can be a server; other clients (on the same LAN) connect to it.
It won't work well outside a LAN, because of NAT.
Normally you would need to run a dedicated server somewhere that would let users connect, and would route messages between them.
Naturally you would want to run all the game logic on the server, and leave to the clients only the display of state, and user input.
Also, a single server could host several games.
Implementation-wise, the socket server from standard library would be a good start; the HTTP server from the same standard library, an even easier start.
Upvotes: 1