擅长:python、mysql、java
<p>正如答案所建议的,我创建了另一个线程来处理输入流,它工作正常。
这是修改后的代码:</p>
<pre><code>sock_send = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
def send_msg(sock):
while True:
data = sys.stdin.readline()
sock.sendto(data, target)
def recv_msg(sock):
while True:
data, addr = sock.recvfrom(1024)
sys.stdout.write(data)
Thread(target=send_msg, args=(sock_send,)).start()
Thread(target=recv_msg, args=(sockfd,)).start()
</code></pre>