我有套接字问题
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
我的错误的任何解决方案?
答案 0 :(得分:0)
要么没有服务器在./hash.sh: line 38: e5491a14c7374e7f2ee18e3095f8ac65: command not found
./hash.sh: line 39: e5491a14c7374e7f2ee18e3095f8ac65: command not found
(UDP)运行,要么中间有防火墙。在本地计算机上运行服务器,让客户端连接到herk-PC:12000
,以确保一切正常。
如果您仍遇到同样的问题,是否在服务器上使用过bind(('localhost',12000))
?
答案 1 :(得分:-1)
#udp_server.py
import socket
bind_host = '127.0.0.1'
bind_port = 7210
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((bind_host, bind_port))
data, addr = sock.recvfrom(4096)
print(data.decode('utf-8'), addr[0], ':', addr[1])
udp客户端
External.click();
Thread.sleep(2000);
External.sendKeys("kevin");
udp_server