服务器接收端,采用pyhon来进行接收,主要使用udp进行通信
mport os,socket,sys,time,string
import threading

time_log=''
time_log1=''
time_record=''

def fun_timer():
global time_log
global time_log1
global time_record
print("yukubaba")
print("current time %s :" %(time_record))
fo=open("time_file.txt","a")
fo.write(str(time_record))
fo.write("\n")
global timer
timer = threading.Timer(1, fun_timer)
timer.start()
timer = threading.Timer(1, fun_timer)
timer.start()

try:
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
sock.bind(('0.0.0.0', 9999))
except:
print("error bind")
sys.exit(1)

print ("----------------start----------------\n")
try:
while 1 :
data,addr=sock.recvfrom(1024)
print data,addr
time_log=str(data)
if(time_log1!=time_log):
time_record=str(time_log)
time_log1=str(time_log)
else:
time_record=""
except KeyboardInterrupt:
print ("------------------ stop-------------\n")
print "good bye"
sys.exit()

数据发送端,采用linux下来进行
for((i=1;i<10000000000;i++))
do
now_date=$(date "+%Y.%m.%d-%H:%M:%S")
printf "$now_date\n"
echo -n "$now_date">/dev/udp/172.18.20.160/9999

sleep 1
done