本文整理汇总了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()
示例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()
示例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()