0
我正在做一個小客戶端\服務器線程聊天,我有一個問題, 如果其中一方正在接收消息,而輸入一個它的中斷這裏輸入的消息是爲了說明輸入消息中斷時收到一條消息
這裏,圖像是線程代碼:
import threading
import socket
class sendTread(threading.Thread):
def __init__(self,soc):
threading.Thread.__init__(self,name='sender')
self.s=soc
def run(self):
while True:
self.s.send(bytes(str(input('>>> ')), 'UTF-8'))
print('sent.')
class recvTread(threading.Thread):
def __init__(self,soc):
threading.Thread.__init__(self,name='recver')
self.s=soc
def run(self):
while True:
data=self.s.recv(1024)
print('\nrecv:',str(data)[2:len(str(data))-1],end="\n>>> ")
我明白爲什麼會發生,但我不知道如何解決它,我會很樂意 的一些幫助和建議:)