其他分享
首页 > 其他分享> > tcp会话

tcp会话

作者:互联网

import socket

sk = socket.socket()
sk.connect(('192.168.31.116', 9999))
while True:
msg = sk.recv(1024)
b=msg.decode('utf-8')
print(msg.decode('utf-8'))
if b=='Q'or b=='q':
break
a = input('会话2')
sk.send(a.encode('utf-8'))
if a =='Q'or a =='q' :
break
sk.close()


# import socket
# sk = socket.socket(type=socket.SOCK_DGRAM)
# while True:
# a = input('会话1')
# sk.sendto(a.encode('utf-8'),('127.0.0.1',9888))
# msg,addr= sk.recvfrom(1024)
# print(msg.decode('utf-8'))
# b = msg.decode('utf-8')
# if a =='Q'or a =='q' or b=='Q'or b=='q':
# break
# sk.close()

标签:decode,utf,socket,tcp,sk,会话,msg
来源: https://www.cnblogs.com/aiyehui/p/16394162.html