如何为python的本地wifi多人游戏设置服务器 [英] How to set up a server for a local wifi multiplayer game for python
问题描述
我正在制作一款卡片反人类游戏(但更好/更适合家庭),并且我已经设置了它,我需要做的就是运行玩家功能,然后是裁判功能,直到有人获胜.我最近问了另一个专门关于我的游戏的问题,但如果您知道通过本地 wifi 设置多人游戏的可靠且万无一失的方法,我希望得到一些帮助.谢谢!
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!
推荐答案
您是否尝试过网络零
?这是一个很棒的网络库,我一直在使用.
Have you tried network zero
? It's an amazing networking library that I use all the time.
安装:
pip install networkzero
PyPI 链接:https://pypi.org/project/networkzero/
文档:https://networkzero.readthedocs.io/en/latest/
代码示例(来自他们的文档页面):
Code sample (from their doc page):
机器/过程 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)
机器/流程 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)
这个库还支持超过 2 个本地 WiFi 连接,阅读文档了解更多信息.
This library also supports more than just 2 connections on the local WiFi, read the docs for more info.
这篇关于如何为python的本地wifi多人游戏设置服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!