Python3 TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是'NoneType'

问题描述 投票:0回答:1

我一直在尝试跟着教程学习,但是当我尝试在客户端窗口中单击创建游戏时,标题出现错误。我最终将代码复制并粘贴到pycharm中,仍然遇到相同的错误。我已经链接了website where the tutorial's source code can be found.

python python-3.x server pygame client
1个回答
0
投票

显然您的游戏客户端无法连接到服务器。

n = Network()
player = int(n.getP()) # <<< here you got an exception

-

class Network:
def __init__(self):
    self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    self.server = "10.11.250.207"
    self.port = 5555
    self.addr = (self.server, self.port)
    self.p = self.connect()  # <<< this value is of None type

def getP(self):
    return self.p

def connect(self):
    try:
        self.client.connect(self.addr)
        return self.client.recv(2048).decode()  # << somewhere here an exception occures
    except:  # <<< but it gets cought here
        pass # <<< and method returns None

您确定您的服务器正在运行?您必须与客户端同时在单独的控制台窗口中运行它。

© www.soinside.com 2019 - 2024. All rights reserved.