其他分享
首页 > 其他分享> > udp

udp

作者:互联网

import socket

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


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

标签:decode,udp,utf,socket,sk,msg,conn
来源: https://www.cnblogs.com/aiyehui/p/16394168.html