[問題] 如何取得notify的file descirptor
小弟目前寫了一個Client-Server架構的程式,是使用PySide 1.1.0寫的程式
Server端會有不定數量的Client來連線
而小弟藉由QSocketNotifier來監聽Client是否有資料可讀
並將QSocketNotifier connect到ReadClientMsg上面
可是卻一直發生如下的錯誤:(XXX值為file descriptor,故為不定值)
"QSocketNotifier: Multiple socket notifiers for same socket XXX and type Read"
而我的目的是想要透過ReadClientMsg得到有資料可讀的file descriptor,並讀取
可是不知道該如何從哪下手,還請各位先進指點一下,謝謝
以下是我的程式碼:
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtNetwork import *
import sys, anyjson
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
#QtCore objects
self.serfd = QTcpServer()
self.serfd.newConnection.connect(self.IncomingClient)
self.clifdlist = list()
#QtGui Objects
self.setWindowTitle("PySer")
self.connectBtn = QPushButton("StartService")
self.connectBtn.clicked.connect(self.BeginService)
self.disconnectBtn = QPushButton("StopService")
self.disconnectBtn.clicked.connect(self.EndService)
allLayout = QHBoxLayout()
allLayout.addWidget(self.connectBtn)
allLayout.addWidget(self.disconnectBtn)
self.setLayout(allLayout)
def BeginService(self):
self.serfd.listen(QHostAddress.Any, 9999)
print "Begin service"
def EndService(self):
self.serfd.close()
for fd in self.clifdlist:
fd.disconnectFromHost()
print "Server close"
app.closeAllWindows()
def IncomingClient(self):
clifd = self.serfd.nextPendingConnection()
clifd.write("Welcome")
notify = QSocketNotifier(clifd.socketDescriptor(),
QSocketNotifier.Read)
notify.activated.connect(self.ReadClientMsg)
self.clifdlist.append(clifd)
def ReadClientMsg(self):
pass
if __name__ == "__main__":
app = QApplication(sys.argv)
form = Form()
form.show()
sys.exit(app.exec_())
--
ˍˍ
很多人在即將失去的時候,不知他即將失去,最後他就真正失去 ▕天險▏
其實,一個不曾失去的人最可憐。因為,他永遠學不會什麼叫珍惜。▕刀藏▏
 ̄ ̄
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.157.91
Python 近期熱門文章
PTT數位生活區 即時熱門文章