動作確認
CentOS 6.5
Unity(C#)などでも作ったがUDPポートでのエコーサーバーのpython版。
(作ったのは Qiita検索)
ポート6000へ送ったものが返される。
udpEcho.py
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('',6000))
s.setblocking(0)
data =''
address = ''
while True:
try:
data,address = s.recvfrom(120)
except socket.error:
pass
else:
print "from:", address
print "recvd:", data
s.sendto("recvd:" + data, address)
結果
$ python udpEcho.py
from: ('192.168.124.132', 55989)
recvd: aaaaa
UDP送信元にはrecvd:aaaaa
などの文字がエコーバックされる。