问题
I'm making a Cards Against Humanity game (but nicer/family friendly-er) and I have it set up where all I need to do is run player functions and then a judge function until someone wins. I recently asked another question specifically about my game, but if you know a solid foolproof way to set up a multiplayer game over local wifi, I would love some help. Thanks!
回答1:
Have you tried network zero
? It's an amazing networking library that I use all the time.
Install:
pip install networkzero
PyPI link: https://pypi.org/project/networkzero/
Docs: https://networkzero.readthedocs.io/en/latest/
Code sample (from their doc page):
Machine/process A:
import networkzero as nw0
address = nw0.advertise("hello")
while True:
name = nw0.wait_for_message_from(address)
nw0.send_reply_to(address, "Hello " + name)
Machine/process B:
import networkzero as nw0
hello = nw0.discover("hello")
reply = nw0.send_message_to(hello, "World!")
print(reply)
reply = nw0.send_message_to(hello, "Tim")
print(reply)
This library also supports more than just 2 connections on the local WiFi, read the docs for more info.
来源:https://stackoverflow.com/questions/62844934/how-to-set-up-a-server-for-a-local-wifi-multiplayer-game-for-python