Python UDP小程序

为了做UDP的测试,采用了nc和Python的服务器端。

nc的安装和使用:

yum install -y nc
nc -vuz 35.194.168.243 5001

 

Python的UDP服务器端小程序:

# -*- coding: UTF-8 -*-
import socket

address = ('0.0.0.0',5001)
s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(address)

while True:
    data, addr = s.recvfrom(2048)
    if not data:
        print 'client has exist'
        break
    print 'received:',data, 'from',addr

s.close()

 

posted @ 2019-05-15 16:22  衡子  阅读(246)  评论(0编辑  收藏  举报