- server--------------
- #!/usr/bin/env python
- # encoding: utf-8
- # Date: 2018/6/7
- from socket import *
- server = socket(AF_INET, SOCK_DGRAM)
- server.bind(('127.0.0.1', 8080))
- res1 = server.recvfrom(1024)
- print('第一次:', res1)
- res2 = server.recvfrom(1024)
- print('第二次:', res2)
- server.close()
- client---------------------
- #!/usr/bin/env python
- # encoding: utf-8
- # Date: 2018/6/7
- from socket import *
- client = socket(AF_INET, SOCK_DGRAM)
- client.sendto(b'hello', ('127.0.0.1', 8080))
- client.sendto(b'world', ('127.0.0.1', 8080))
- client.close()
来源: http://www.bubuko.com/infodetail-2646227.html