2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

python > udp > echo server

Last updated at Posted at 2015-11-12
動作確認
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などの文字がエコーバックされる。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?