Can*_*erk 6 python sockets udp python-3.x
我有套接字问题
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()
Run Code Online (Sandbox Code Playgroud)
这段代码给我错误
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
Run Code Online (Sandbox Code Playgroud)
我的错误有什么解决办法吗?
要么您没有在herk-PC:12000(UDP) 上运行服务器,要么中间有防火墙。在本地计算机上运行服务器并让客户端连接到localhost:12000以确保一切正常。
如果您仍然遇到同样的问题,您是否bind(('localhost',12000))在您的服务器上使用过?
| 归档时间: |
|
| 查看次数: |
13987 次 |
| 最近记录: |