Skip to content

Commit d72dc61

Browse files
committed
Create udp_server.py
1 parent d43730a commit d72dc61

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

socket/udp_server.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
'a udp server example which send time to client.'
5+
6+
import socket
7+
8+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
9+
# 绑定端口:
10+
s.bind(('127.0.0.1', 9999))
11+
print 'Bind UDP on 9999...'
12+
while True:
13+
# 接收数据:
14+
data, addr = s.recvfrom(1024)
15+
print 'Received from %s:%s.' % addr
16+
s.sendto('Hello, %s!' % data, addr)

0 commit comments

Comments
 (0)