Python udpチャットルームがスレッドを使用していない場合、いくつかの興味深い理解
スレッドがまだ使用されていない場合、いくつかの興味深い理解
from socket import *
import threading
udp_socket = socket(AF_INET, SOCK_DGRAM)
bind_addr = ('', 8899)
udp_socket.bind(bind_addr)
def send_data(addr):
data = input('') # , while True , ,data
#
udp_socket.sendto(data.encode('gbk'), addr)
def receive_data():
while True:
content, addr = udp_socket.recvfrom(1024)
print('start')
print(' %s, %s' % (content.decode('gbk'), addr[0]))
send_data(addr) # socket ,
# input
receive_data()
udp_socket.close()