python 网络编程-02 多进程的交互案例
server.py
import socket from threading import Thread def Server(): server = socket.socket() server.bind(('127.0.0.1', 8000)) server.listen(5) while True: conn, addr = server.accept() Thread(target=talk,args=[conn,]).start() def talk(connect): while True: msg = connect.recv(1024) print(msg) if msg.decode('utf-8') == 'bye': break answer = "我是server!" connect.send(answer.encode('utf-8')) connect.close() if __name__ == '__main__': Server()
client.py
import socket if __name__ == '__main__': client = socket.socket() client.connect(('127.0.0.1', 8000)) while True: send_msg = input("请输入") client.send(send_msg.encode()) if send_msg == "bye": break msg = client.recv(1024) print(msg.decode('utf-8')) client.close()
相关推荐
架构技术交流 2020-04-14
Unimen 2020-06-25
MAC2007 2020-06-06
安辉 2020-05-05
diediexiaomi 2020-04-21
taishanduba 2020-04-11
kkpiece 2020-03-03
vanturman 2020-02-10
朱建伟 2020-01-10
jackalwb 2020-01-01
TinyDolphin 2020-01-10
shengge0 2020-01-08
apowerfulman 2020-01-07
OwenJi 2019-12-29
HongKongPython 2019-12-29
zhouhaihua00 2019-12-26
htofly 2019-12-16