現在、PC の GUI がソケットごとにサーバーと通信できるようにしようとしています。
ここにGUIのコードの一部があります:
def listenToServer(self):
""" keep listening to the server until receiving 'All Contracts Finished' """
self.feedbackWindow.appendPlainText('--Executing the Contracts, Listening to Server--')
contentsListend = ''
while contentsListend != 'All Contracts Finished':
#keep listen from the socket
contentsListend = self.skt.recv(1024)
#make the GUI show the text
self.feedbackWindow.appendPlainText(contentsListend)
反対側では、サーバーはデータを 1 つずつ送信しますが、間隔があります。サーバーをシミュレートするテスト コードは次のとおりです。
for i in range(7):
print 'send back msg, round: ', i # this will be printed on the screen of the server, to let me know that the server works
time.sleep(1) # make some interval
# c is the connected socket, which can send messages
# just send the current loop number
c.send('send back msg' + str(i))
c.send('All Contracts Finished')
c.close()# Close the connection
これで、GUI がサーバー内の for ループ全体の後に受信したメッセージのみを表示するという問題を除いて、すべてが機能します。サーバーとGUIを実行したら。サーバー側はメッセージを正しい速度で画面に 1 つずつ出力しますが、GUI は応答がなく、更新されません。プログラムの最後まで、7 行すべてが GUI 側で一斉に発生します。後で PC のこの GUI を使用してサーバーの状態を検査できるように、それらを 1 つずつ表示したいと考えています。
誰でも助けてくれますか、どうもありがとう!