作者godman362 (卯)
看板Python
标题[问题] 如何取得notify的file descirptor
时间Thu May 17 07:40:25 2012
小弟目前写了一个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