当前位置: 首页>>代码示例>>Python>>正文


Python Client.disconnect方法代码示例

本文整理汇总了Python中Client.Client.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python Client.disconnect方法的具体用法?Python Client.disconnect怎么用?Python Client.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Client.Client的用法示例。


在下文中一共展示了Client.disconnect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import disconnect [as 别名]
    def run(self) :
        while True :
            #采用select模型
            #rs : 就绪读
            #ws : 就绪写
            #es : 就绪的错误信息
            rs , ws ,es = select.select(self.inputs , [] ,[])
            for r in rs : 
                if r is self.server:
                    conn , addr = self.server.accept()
                    print 'get conn from ' , addr
                    client = Client(conn , addr)
                    self.clientList[self.getIndex(addr)] = client
                    menuHandler = MenuHandler()
                    client.setHandler(menuHandler)
                    self.inputs.append(conn)
                else :
                    try :
                        clientIndex = self.getIndex(r.getpeername())
                        client = self.clientList[clientIndex]
                        if not client:
                            print 'error , can not find the client :' ,clientIndex
                        data = r.recv(2048)
                        disconnected = False
                        if not data :
                            disconnected = True
                        else :
                            client.recv(data)

                    except Exception ,e:
                        print e
                        disconnected = True

                    if disconnected:
                        print r.getpeername() , 'disconnected'
                        client = self.clientList[self.getIndex(r.getpeername())] 
                        client.disconnect()
                        del self.clientList[self.getIndex(r.getpeername())] 
                        self.inputs.remove(r)
开发者ID:cuzn,项目名称:finalProj,代码行数:41,代码来源:main.py

示例2: testClientConnection

# 需要导入模块: from Client import Client [as 别名]
# 或者: from Client.Client import disconnect [as 别名]

#.........这里部分代码省略.........
        deferredResult(def1)

        def2 = self.cFactory.login(credentials.UsernamePassword("Matias","matias"), client=self.myClient2.cc)
        def2.addCallback(self.getRoot, 2)
        def2.addErrback(self.failure, "Error al conectarse el cliente2")
        deferredResult(def2)

    def tearDown(self):
        reactor.removeAll()
        deferredResult(self.server.stopListening())

    def testAddTextBox(self):
        deferredResult(self.myClient.wb.addTextBox(20, 20))
        self.assertEqual(self.myClient.wb.foreignObjectsCount(), 0)
        self.assertEqual(self.myClient2.wb.foreignObjectsCount(), 1)

    def testInsertChars(self):
        deferredResult(self.myClient.wb.addTextBox(20, 20))
        deferredResult(self.myClient.wb.insertChars(self.myClient.wb.wbCurrent, 0, "fooBarBaz"))
        self.assertEqual(self.myClient.wb.foreignObjectsCount(), 0)
        wb2 = self.myClient2.wb
        self.assertEqual(wb2.foreignObjectsCount(), 1)
        self.assertEqual(wb2.itemcget(wb2.foreignObjects.values()[0], "text"), "fooBarBaz")

    def testDeleteChars(self):
        deferredResult(self.myClient.wb.addTextBox(20, 20))
        deferredResult(self.myClient.wb.insertChars(self.myClient.wb.wbCurrent, 0, "fooBarBaz"))
        deferredResult(self.myClient.wb.deleteChars(self.myClient.wb.wbCurrent, 3, 4))
        self.assertEqual(self.myClient.wb.foreignObjectsCount(), 0)
        wb2 = self.myClient2.wb
        self.assertEqual(wb2.foreignObjectsCount(), 1)
        self.assertEqual(wb2.itemcget(wb2.foreignObjects.values()[0], "text"), "foorBaz")

    def failure(self, msg, who=0):
        print "error: ", msg
        self.done = True

    def getRoot(self, perspective, who):
        d = perspective.callRemote("getWbServer")
        d.addCallback(self.success, who)

    def success(self, root, who):
        if who == 1:
            self.myClient.setRoot(root)
        else:
            self.myClient2.setRoot(root)

    def localDeleteChars(self, data):
        self.myClient.wb.deleteChars(self.myClient.wb.wbCurrent, 3, 4)

    def finished(self):
        self.done = True
        try:
            self.timeout.cancel()
        except (error.AlreadyCancelled, error.AlreadyCalled):
            pass

    def testServerStatusNewText(self):
        deferredResult(self.myClient.wb.addTextBox(20, 20))
        current = self.myClient.wb.wbCurrent
        self.assert_(self.wbServer.wbStatus.has_key(self.wbServer.itemId(3, current)))

    def testServerStatusEditText(self):
        deferredResult(self.myClient.wb.addTextBox(20, 20))
        deferredResult(self.myClient.wb.insertChars(self.myClient.wb.wbCurrent, 0, "fooBarBaz"))
        current = self.myClient.wb.wbCurrent
        dict = self.wbServer.wbStatus[self.wbServer.itemId(3, current)]
        self.assertEqual(dict["text"], "fooBarBaz")
        self.assertEqual(dict["x"], 20)
        self.assertEqual(dict["y"], 20)
        self.assertEqual(dict["owner"].avId, 3)

    def testServerStatusClientConnect(self):
        dict = self.wbServer.wbStatus
        for a in dict.keys():
            self.assert_(self.myClient.wb.foreignObjects.has_key(a))

    def testServerStatusClientDisconnect(self):
        deferredResult(self.myClient.disconnect())
        self.assert_(3 not in self.wbServer.wbClients)

    def testServerStatusClientAdd(self):
        deferredResult(self.myClient.wb.addTextBox(20, 20))
        deferredResult(self.myClient.wb.insertChars(self.myClient.wb.wbCurrent, 0, "fooBarBaz"))
        ddict = self.wbServer.wbStatus
        for a in ddict.keys():
            self.assert_(self.myClient2.wb.foreignObjects.has_key(a))
            tbox = self.myClient2.wb.foreignObjects[a]
            self.assertEqual(self.myClient2.wb.itemcget(tbox, "text"),ddict[a]["text"])

    def testServerStatusClientModify(self):
        deferredResult(self.myClient.wb.addTextBox(20, 20))
        deferredResult(self.myClient.wb.insertChars(self.myClient.wb.wbCurrent, 0, "fooBarBaz"))
        deferredResult(self.myClient.wb.deleteChars(self.myClient.wb.wbCurrent, 3, 5))
        current = self.myClient.wb.wbCurrent
        ddict = self.wbServer.wbStatus[self.wbServer.itemId(3, current)]
        self.assertEqual(self.myClient.wb.itemcget(current, "text"), "fooBaz")
        self.assertEqual(ddict["text"], "fooBaz")
        self.assertEqual(ddict["x"], 20)
        self.assertEqual(ddict["y"], 20)
开发者ID:mgaitan,项目名称:beppo,代码行数:104,代码来源:testClientConnection.py


注:本文中的Client.Client.disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。