#server.py
from gevent import monkey;monkey.patch_all()
import socket
import gevent
sk = socket.socket()
sk.bind(('127.0.0.1',8080))
sk.listen()
def talk(conn):
conn.send(b'hello')
print(conn.recv(1024).decode('utf-8'))
conn.close()
while True:
conn,addr = sk.accept()
gevent.spawn(talk,conn)
sk.close()
#client.py
import socket
sk =socket.socket()
sk.connect(('127.0.0.1',8080))
print(sk.recv(1024).decode('utf-8'))
msg = input('>>>'.encode('utf-8'))
sk.send(msg)
sk.close()
相关文章
- 03-20Python并发编程-协程实现socketserver
- 03-2038 协程 greenlet模块实现并发 Gevent
- 03-20协程+IO切换实现并发
- 03-20并发编程之 协程
- 03-20并发编程~~~协程~~~greenlet模块, gevent模块
- 03-20Python 之并发编程之协程
- 03-20python 并发编程 协程池
- 03-20python 协程编程之gevent
- 03-20进程池和线程池、协程、TCP单线程实现并发
- 03-20Python并发编程——多线程与协程