Home > other >  A python socket. Sendto () command issued two packets
A python socket. Sendto () command issued two packets

Time:12-29

Masters,

The younger brother in a UDP server with python, the script is as follows:

#/usr/bin/python3

The from socketserver import ThreadingUDPServer, DatagramRequestHandler
The import socket

The class MyDatagramRequestHandler (DatagramRequestHandler) :
Def handle (self) :
Print (self. Client_address)
Data=https://bbs.csdn.net/topics/self.request [0]
The socket=self. Request [1]
# print (Data)

Sockets sendto (b 'OKOK, self. Client_address)

If __name__=="__main__" :

HostIP="192.168.15.2"
UdpPort=9001

Server_Address=(HostIP, UdpPort)
Print (" Starting the UDP server port on % s % d... "% (HostIP, UdpPort))
Udp_server=ThreadingUDPServer (Server_Address MyDatagramRequestHandler)
Udp_server. Serve_forever ()


But I use wires hark monitoring data packets, found that the above procedure after receiving UDP data from the client, in the use of the socket. Sendto () when the echo data,
Will send two packets in a row, the first packet is correct, and the second will issue an empty packet,



I use wireshark capture package is above, we can find that, two consecutive data is sent to the client. Can't figure out what was going on,

But from the client end with the same sendto () of package is normal, only a packet sent to the Udp server side, below is the client side code:

The sock=socket. The socket (socket. AF_INET, socket. SOCK_DGRAM)

Server_address=(HostIP, UdpPort)

Message="b" OK "
Sent=the sock. Sendto (Message, server_address)

After Server side what the problem is to ask each tall person to give directions, thank you thank you very much,

CodePudding user response:

Solved, could you tell me how to solve
  • Related