from socket import *
from threading import Thread
udp_socket = None
dest_ip = ''
dest_port = 0
def send():
while True:
content = input('<<<')
udp_socket.sendto(content.encode(), (dest_ip, dest_port))
def recv():
while True:
data = udp_socket.recvfrom(1024)
content, address = data
ip, port = address
print('\r>>>[%s %d] %s' % (ip, port, content.decode()))
print('<<<', end='')
def main():
global udp_socket, dest_ip, dest_port
udp_socket = socket(AF_INET, SOCK_DGRAM)
udp_socket.bind(('', 7788))
dest_ip = input('Please enter the IP: ')
dest_port = int(input('Please enter the port: '))
ts = Thread(target=send)
tr = Thread(target=recv)
ts.start()
tr.start()
if __name__ == '__main__':
main()
When recv()
is called, print('<<<', end='')
is not printed out. Is there anybody who knows the reason behind it? By the way, I run it in both of Pycharm IDE and Linux OS. But the bug appears in both.