Features Datagram Protocol

udp protocol no problem stick package, the maximum amount of data transferred stably 512 bytes 
ntp server (server time), time synchronization
data packets: a data is sent each carrying a header
must be pitch-catch
from socket import *

client=socket(AF_INET,SOCK_DGRAM)

client.sendto(b'hello',('127.0.0.1',8081))
client.sendto(b'world',('127.0.0.1',8081))
client.sendto(b'egon',('127.0.0.1',8081))
Client
from Socket Import *
 # UDP protocol does not stick package problem, the maximum amount of stable transfer 512 bytes of data 
# NTP server (server time), the time synchronization 
Server = Socket (AF_INET, SOCK_DGRAM) 
server.bind (( ' 127.0.0.1 ' , 8081 ))
 # must be a pitch-catch 
Print (server.recvfrom (1024 ))
 Print (server.recvfrom (1024 ))
 Print (server.recvfrom (1024))
Server

 

Guess you like

Origin www.cnblogs.com/zhouhao123/p/11257631.html