2013-04-21 94 views
2

我剛開始學習python與樹莓一起工作,我的最終目標是通過在樹莓之間創建一個p2p網絡來創建客戶端/服務器應用程序。我選擇使用庫asyncore來創建客戶端和服務器,並且最初爲圖形創建pygame,現在我試圖使用PySide,但是我遇到了問題。Pyside客戶端和服務器

如何將asyncore.loop()集成到pyside的主循環中?

+0

我想你可以把asyncore到一個單獨的線程。所以你會有2個並行循環。你需要什麼asyncore?你爲什麼不能用pyside來做到這一點? – gatto 2013-04-21 13:56:43

+0

我希望每一個樹莓都能與他人溝通,改變屏幕上顯示的內容。 – Anubis4815 2013-04-21 14:18:22

+0

我想弄清楚如何採取建議 – Anubis4815 2013-04-21 14:22:43

回答

0

你試過嗎?

class ClientThread(threading.Thread): 

# Start the thread for the socket 
def __init__(self, server, port, user, gui): 
    threading.Thread.__init__(self) 
    self.client = ClientConnection(server, int(port), user, gui) 

# Run the asyncore loop 
def run(self): 
    try: 
     asyncore.loop() 
    except: 
     return 0 

也許它可以是有用的,你這個例子: https://github.com/absolution/Month-2--Chat-Client-/blob/master/ClientGUI.py