我正在嘗試建立與 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
提交
取消