我正在尝试建立与 server.py 的连接,但 client.py 输出此错误Traceback (most recent call last): File "C:\Users\Nathan\Desktop\Coding\Langs\Python\Projects\Chatting Program\Client.py", line 15, in <module> clientsocket.connect((host, port)) # Connects to the serverTypeError: an integer is required (got type str)这是我的代码...## CLIENT.PYfrom socket import *import sockethost = input("Host: ")port = input("Port: ")#int(port)username = input("Username: ")username = "<" + username + ">"print(f"Connecting under nick \"{username}\"")clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Creates socketclientsocket.connect((host, port)) # Connects to the serverwhile True: Csend = input("<MSG> ") # Input message Csend = f"{username} {Csend}" # Add username to message clientsocket.send(Csend) # Send message to ONLY the server如果我的 server.py 有问题,那么这是代码## SERVER.PYfrom socket import *import socketimport selecthost_name = socket.gethostname()HOST = socket.gethostbyname(host_name) PORT = 12345print(f"Server Info\nHOST: {HOST}\nPORT: {PORT}")serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)serversocket.bind((HOST, PORT))serversocket.listen(5)clientsocket, address = serversocket.accept()print(address)with clientsocket: while True: Srecv = clientsocket.recv(1024) print(f"{username} - {address}: {Srecv}") # Add server time to message before sending clientsocket.sendall(Srecv)我尝试过将主机和端口转换为str,int和浮点数,但它只能成功转换为str。任何帮助将不胜感激。提前致谢!
添加回答
举报
0/150
提交
取消