python 3 TCP简单小程序
2015-11-30 17:49
751 查看
ChatServer.py
import socket
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print (sock)
sock.bind(('127.0.01',8000))
sock.listen(2)
clientsocket,address=sock.accept();
print('connection from ',address);
while 1:
data=clientsocket.recv(1024)
if not data :break
print('received from client',repr(data))
print('echo',repr(data))
clientsocket.send(data)
clientsocket.close()
sock.close()
ChatClient.py
import socket
clientsocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
clientsocket.connect(('127.0.0.1',8000))
while 1:
data=input("请输出要传达的消息")
clientsocket.send(data.encode())
if not data:break
newdata=clientsocket.recv(1024)
print('received from server:',repr(newdata))
clientsocket.close()
import socket
sock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
print (sock)
sock.bind(('127.0.01',8000))
sock.listen(2)
clientsocket,address=sock.accept();
print('connection from ',address);
while 1:
data=clientsocket.recv(1024)
if not data :break
print('received from client',repr(data))
print('echo',repr(data))
clientsocket.send(data)
clientsocket.close()
sock.close()
ChatClient.py
import socket
clientsocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
clientsocket.connect(('127.0.0.1',8000))
while 1:
data=input("请输出要传达的消息")
clientsocket.send(data.encode())
if not data:break
newdata=clientsocket.recv(1024)
print('received from server:',repr(newdata))
clientsocket.close()
相关文章推荐
- The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from
- webview显示https协议内容
- iOS如何在工程中使用第三方(网络)图片
- PEP 0476 -- Enabling certificate verification by default for stdlib http clients
- 用netstat对TCP状态分析
- 关于http请求和webservice请求的了解?
- java Tcp/Udp区别
- iOS开发网络篇—文件的上传
- iOS开发网络篇—监测网络状态
- tomcat下配置https环境
- 网络爬虫基本原理(二)
- 使用HttpCLient处理HTTP请求
- okhttpclient 文件断点上传
- iOS开发网络篇—发送json数据给服务器以及多值参数
- 网络爬虫基本原理(一)
- iOS开发网络篇—数据缓存
- 网络获取图片
- 定位网络攻击一例
- 卷积神经网络
- spring 4.x下让http请求返回json串