當前位置: 首頁>>代碼示例>>Python>>正文


Python Server.close方法代碼示例

本文整理匯總了Python中Server.close方法的典型用法代碼示例。如果您正苦於以下問題:Python Server.close方法的具體用法?Python Server.close怎麽用?Python Server.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Server的用法示例。


在下文中一共展示了Server.close方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import Server [as 別名]
# 或者: from Server import close [as 別名]
def main():

  ADDR = getArg( "a", "127.0.0.1", "Address" )
  PORT = getArg( "p", 5005, "Port" )
  MAX_CLIENTS = getArg( "m", 50, "Max Clients" )

  # Create server
  SERVER = Server( ADDR, PORT, MAX_CLIENTS )

  # Server main loop
  SERVER.main()

  SERVER.close()
開發者ID:Alfwich,項目名稱:school,代碼行數:15,代碼來源:ChatServer.py

示例2: PyChatClient

# 需要導入模塊: import Server [as 別名]
# 或者: from Server import close [as 別名]
class PyChatClient(QMainWindow, Ui_ChatWindow):

    sendSignal = pyqtSignal(str)

    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)

        self.setupUi(self)

        # self.clients = []
        if sys.platform == 'darwin':
           self.menubar.setNativeMenuBar(False)

        # self.pc_names = {}
        # self.pc_names['localhost'] = 'Randy'

        self.server = Server(self)
        self.server.message.connect(self.receiveMessage)
        self.server.start()
        
        self.createActions()
        self.createTrayIcon()

        self.sendButton.clicked.connect(self.send_message)
        self.lineEdit.returnPressed.connect(self.send_message)
        self.actionQuit.triggered.connect(qApp.quit)

        self.trayIcon.setIcon(QIcon(':images/trash.svg'))
        self.trayIcon.show()


    def showDialog(self):
        ip_address = socket.gethostbyname('CTCDCSVYQ1.CCPS.WAN')
        #ip_address = socket.gethostbyname('localhost')
        self.gui = PyChatGUI(parent=self, socket_=None, ip=ip_address)

    def receiveMessage(self, socket_):
        PyChatGUI(self, socket_)

    def connectToServer(self):
        self.client = Client(self)
        self.client.start()
        self.sendSignal.connect(self.client.send_message)
        self.client.message.connect(self.receiveMessage)

    def sendMessage(self):
        self.textBrowser.append(self.lineEdit.text())
        self.sendSignal.emit(self.lineEdit.text())
        self.lineEdit.setText('')
        self.lineEdit.setFocus()

    def getConnectedPcName(self, socket_):

        return 'Mr. Valis'

    def createActions(self):

        self.connectAction = QAction("&Send Message", self,
                triggered=self.showDialog)

        self.quitAction = QAction("&Quit", self,
                triggered=self.quit)

    def addPCActions(self):
        '''To be overridden in a child class'''
        pass

    def quit(self):
        self.server.close()
        qApp.quit()

    def createTrayIcon(self):
        self.trayIconMenu = QMenu(self)
        self.trayIconMenu.addAction(self.connectAction)
        self.addPCActions()
        self.trayIconMenu.addSeparator()
        self.trayIconMenu.addAction(self.quitAction)

        self.trayIcon = QSystemTrayIcon(self)
        self.trayIcon.setContextMenu(self.trayIconMenu)

    def setVisible(self, visible):
        self.connectAction.setEnabled(self.isMaximized() or not visible)
        super(PyChatClient, self).setVisible(visible)

    def closeEvent(self, event):
        if self.trayIcon.isVisible():
            QMessageBox.information(self, "Systray",
                    "The program will keep running in the system tray. To "
                    "terminate the program, choose <b>Quit</b> in the "
                    "context menu of the system tray entry.")
            # self.hide()
            # self.client.running = False
            event.ignore()
開發者ID:xran-deex,項目名稱:PyChat,代碼行數:96,代碼來源:PyChatClient.py

示例3: Server

# 需要導入模塊: import Server [as 別名]
# 或者: from Server import close [as 別名]
from Server import *
import sys

try:
	ser = Server(9000)

	while True:
	    ser.recieve()
except KeyboardInterrupt:
	ser.close()
	print "\nexited cleanly"
	sys.exit()
開發者ID:NathanMer,項目名稱:Astroid_Game,代碼行數:14,代碼來源:RunServer.py


注:本文中的Server.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。