gpt4 book ai didi

python - 套接字Python 3 UDP ConnectionResetError : [WinError 10054] An existing connection was forcibly closed by the remote host

转载 作者:行者123 更新时间:2023-12-03 11:56:24 49 4
gpt4 key购买 nike

我有 socket 问题

import socket

serverName = "herk-PC"
serverPort = 12000

clientSocket = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)

message = input('input lowercase sentence:')

clientSocket.sendto(message.encode('utf-8'),(serverName, serverPort))

modifiedMessage, serverAddress = clientSocket.recvfrom(2048)


print (modifiedMessage.decode('utf-8'))

clientSocket.close()

这段代码给我错误
Traceback (most recent call last):
File "J:\Sistem Jaringan\Task I\client.py", line 12, in <module>
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

我的错误有解决办法吗?

最佳答案

您可能没有在herk-PC:12000(UDP)上运行的服务器,或者两者之间有防火墙。在本地计算机上运行服务器,并让客户端连接到localhost:12000,以确保一切正常。

如果仍然存在相同的问题,是否在服务器上使用了 bind(('localhost',12000))

关于python - 套接字Python 3 UDP ConnectionResetError : [WinError 10054] An existing connection was forcibly closed by the remote host,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29182546/

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