gpt4 book ai didi

Python PodSixNet 错误

转载 作者:行者123 更新时间:2023-12-01 04:40:07 25 4
gpt4 key购买 nike

我尝试在我的一款游戏中使用名为 PodSixNet 的多人游戏模块,但在尝试运行客户端时,assyncore.py 出现错误。然而,服务器运行完美。我开发了简单的测试客户端和服务器程序,但是当我运行客户端时仍然遇到相同的错误。下面分别是我的客户端和服务器程序:

import PodSixNet, time
from PodSixNet.Connection import ConnectionListener, connection
from time import sleep

class MyNetworkListener(ConnectionListener):

connection.Connect()


def Network(self, data):
print data


gui = MyPlayerListener()
while 1:
connection.Pump()
gui.Pump()

.

import PodSixNet, time
from time import sleep
from PodSixNet.Channel import Channel
from PodSixNet.Server import Server

class ClientChannel(Channel):

def Network(self, data):
print data

class MyServer(Server):

channelClass = ClientChannel

def Connected(self, channel, addr):
print "new connection:", channel

myserver = MyServer()

while True:
myserver.Pump()
sleep(0.0001)

这是我运行客户端时返回的错误:

    Traceback (most recent call last):
File "C:\Users\Matt\Desktop\The 37th Battalion\PodSixNet Tests\client.py", line 5, in <module>
class MyNetworkListener(ConnectionListener):
File "C:\Users\Matt\Desktop\The 37th Battalion\PodSixNet Tests\client.py", line 7, in MyNetworkListener
connection.Connect()
File "C:\Python27\lib\asyncore.py", line 418, in __getattr__
retattr = getattr(self.socket, attr)
File "C:\Python27\lib\asyncore.py", line 418, in __getattr__
retattr = getattr(self.socket, attr)
File "C:\Python27\lib\asyncore.py", line 418, in __getattr__
retattr = getattr(self.socket, attr)
File "C:\Python27\lib\asyncore.py", line 418, in __getattr__
retattr = getattr(self.socket, attr)

此错误一直持续到我达到最大递归深度。我们将不胜感激。

谢谢,大卫

最佳答案

首先,您必须告诉服务器应该监听哪个端口:

server.py

import PodSixNet, time
from time import sleep
from PodSixNet.Channel import Channel
from PodSixNet.Server import Server

class ClientChannel(Channel):

def Network(self, data):
print data

class MyServer(Server):

channelClass = ClientChannel

def __init__(self, *args, **kwargs):
Server.__init__(self, *args, **kwargs)

def Connected(self, channel, addr):
print "new connection:", channel

# use the localaddr keyword to tell the server to listen on port 1337
myserver = MyServer(localaddr=('localhost', 1337))

while True:
myserver.Pump()
sleep(0.0001)

然后,客户端必须连接到此端口:

client.py

import PodSixNet, time
from PodSixNet.Connection import ConnectionListener, connection
from time import sleep

class MyNetworkListener(ConnectionListener):

def __init__(self, host, port):
self.Connect((host, port))

def Network(self, data):
print data

# tell the client which server to connect to
gui = MyNetworkListener('localhost', 1337)
while 1:
connection.Pump()
gui.Pump()

您不必在 connection 上调用 Connect(),而是在 ConnectionListener 实例上调用。

enter image description here

关于Python PodSixNet 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30918451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com