python socket了解使用
#服务器端import socketserver = socket.socket()server.bind((‘localhost‘,6969))#绑定要监听端口server.listen()#监听conn, addr = server.accept() # 等电话打进来# conn就是客户端连过来而在服务器端为其生成的一个连接实例print(conn, addr)while True: print(‘电话来了‘) data=conn.recv(1024) print(‘recv:‘,data) conn.send(data.upper())server.close()
#客户端import socketclient= socket.socket()#声明socket类型,同时生成socket连接对象client.connect((‘localhost‘,6969))while True: msg = input(">>:").strip() if len(msg)== 0:continue client.send(msg.encode("UTF-8")) data= client.recv(1024) print(‘recv:‘,data.decode())client.close()
相关推荐
digwtx 2020-09-14
efeve 2020-09-14
一叶梧桐 2020-10-14
lzzyok 2020-10-10
poplpsure 2020-08-17
libowenhit 2020-07-23
luckykapok 2020-07-06
hongsheyoumo 2020-06-27
jannal 2020-06-21
lanmantech 2020-06-16
咻咻ing 2020-06-16
weibingbingnet 2020-06-14
woyanyouxin 2020-06-04
houjinkai 2020-06-03
txj 2020-06-02
Chydar 2020-05-15
小木兮子 2020-05-14