python client and server
来源:互联网 发布:软性毒品 知乎 编辑:程序博客网 时间:2024/06/04 18:38
client段代码如下:
import sysfrom socket import *serverHost = 'localhost'serverPort = 1002message = [b'Hello network world']if len(sys.argv)> 1: serverHost =sys.argv[1] if len(sys.argv) >2: message = (x.encode() for x in sys.argv[2:]) sockobj = socket(AF_INET , SOCK_STREAM) sockobj.connect((serverHost , serverPort)) for line in message: sockobj.send(line) data = sockobj.recv(1024) print "client received:" , data sockobj.close()
放到client端机器上,运行的时候输入 python client localhost abcdefg ,其中abcdefg是发送的信息。
from socket import *myHost = ''myPort = 1002sockobj = socket(AF_INET , SOCK_STREAM)sockobj.bind((myHost , myPort))sockobj.listen(5)while True: connection , address = sockobj.accept() print "Server connected by" , address while True: data = connection.recv(1024) print "*"*30 print data if not data:break connection.send(b'Echo=>'+data) connection.close()
这段代码就这么简单,就完成了两个计算机基于TCP/IP的通讯。
参考资料:
http://www.cnblogs.com/vamei/archive/2012/10/30/2744955.html
http://www.lpfrx.com/archives/133/
- python client and server
- python server and client
- python https server and client
- Python UDP Server and Client
- Thrift tutorial(python server and php client)
- Simple HTTP Server and Client in Python
- Python学习之client and server篇一:python 实现简单client与server
- svn client and server
- client and server direct
- C++ Server and Client
- socket ---> server and client
- tcp client and server
- Client And Server
- ROS server and client
- client/server程序-python
- Python UDP Server Client
- python socket-server-client
- python server, client
- CreateMutex
- Window7 Professional(64位) 安装IIS7.5 运行WCF Web service(*.svc文件)
- 基于LwIP socket的TCP客户端
- ibatis 迭代查询
- 从一个经典案例看优化mapred.map.tasks的重要性
- python client and server
- 远程监控程序的实现
- CSS display属性
- 基础总结篇之五:BroadcastReceiver应用详解
- SQL利用Case When Then多条件判断
- 蚁群算法+LEACH 点滴(一) 随机数产生
- 【且听我说“镶嵌数据集建库”】6、操作:原始影像建库
- 线程中CreateEvent和SetEvent及WaitForSingleObject的用法
- C++内联函数与C语言宏的比较