代码1
from socket import *
from threading import Thread
s=socket(AF_INET,SOCK_DGRAM)
def fasong():
while True:
data = input("请输入内容:")
s.sendto(data.encode(), ("192.168.1.8", 8080))
def jieshou():
while True:
s.bind(("",8585))
recvdata=s.recvfrom(1024)
print(recvdata[0].decode())
t1=Thread(target=fasong)
t2=Thread(target=jieshou)
t1.start()
t2.start()
代码2:
from socket import *
from threading import Thread
s=socket(AF_INET,SOCK_DGRAM)
def fasong():
while True:
data=input("请输入内容:")
s.sendto(data.encode(),("192.168.1.8",8585))
def jieshou():
while True:
s.bind(("",8080))
recvdata=s.recvfrom(1024)
print(recvdata[0].decode())
t1=Thread(target=fasong)
t2=Thread(target=jieshou)
t1.start()
t2.start()
运行结果:
问题:
老师请问一下,我这里使用全双工实现聊天室,开辟了两个线程,可为什么会出现这个错误,而且每次只能输入发送内容,不能接收,好像用来接收数据的t2线程没有用上,一直没有数据接收到,请问老师这个是什么原因?