python网络编程-使用socket实现S/C之间的UDP通信
2014-04-21 00:52
1046 查看
server端:
本文出自 “muahao” 博客,请务必保留此出处http://muahao.blog.51cto.com/8176010/1399219
#!/usr/bin/python from socket import * from time import ctime HOST='' PORT=21567 BUFSIZ=1024 ADDR=(HOST,PORT) udpSerSock = socket(AF_INET,SOCK_DGRAM) udpSerSock.bind(ADDR) while True: print 'waiting for message..' data,addr = udpSerSock.recvfrom(BUFSIZ) udpSerSock.sendto('[%s] %s' % (ctime(),data),addr) print '...received from and return to:',addrclient端:
#!/usr/bin/python from socket import * HOST = 'localhost' PORT = 21567 BUFSIZ = 1024 ADDR = (HOST,PORT) udpCliSock = socket(AF_INET,SOCK_DGRAM) while True: data = raw_input('>') if not data: break udpCliSock.sendto(data,ADDR) data,ADDR = udpCliSock.recvfrom(BUFSIZ) if not data: break print dataudpClisock.close()
本文出自 “muahao” 博客,请务必保留此出处http://muahao.blog.51cto.com/8176010/1399219
相关文章推荐
- python网络编程-使用socket实现S/C之间的tcp通信
- Python网络编程使用select实现socket全双工异步通信功能示例
- 使用JAVA实现Socket通信,TCP、UDP简析。
- windows下使用php socket 和 html5 websocket实现服务器和客户端之间通信
- 简单使用SOCKET,TCP,UDP模式之间的通信
- Android 使用socket实现两个真机之间的通信
- Android 使用socket实现两个真机之间的通信
- Python实现socket通信(udp)
- JAVA系列课程讲座二:使用Socket通信实现简单聊天通信程序(UDP方式)
- Python 实现socket通信 (UDP)
- [转] 最简单的使用UDP通信的Python Socket例子
- python-基于UDP通信的套接字,socketserver模块的使用
- Python基于socket模块实现UDP通信功能示例
- Linux中使用C语言实现基于UDP协议的Socket通信示例
- Python的socket网络编程1 sock简单通信实现
- 如何使用socket实现unity和Winform之间通信
- python——使用socket模块实现客户端与服务端通信
- Python网络编程之socket编程(一)--使用TCP和UDP客户端和服务器通信
- 使用JAVA实现Socket通信,TCP、UDP简析。
- Python使用socket实现简单的文件传输并校验