Python并发编程-协程实现socketserver

#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()
上一篇:vim matchit 自定义配对关键字之间的跳转


下一篇:ASP.NET仿新浪微博下拉加载更多数据瀑布流效果