本文整理匯總了Python中Server.start方法的典型用法代碼示例。如果您正苦於以下問題:Python Server.start方法的具體用法?Python Server.start怎麽用?Python Server.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Server
的用法示例。
在下文中一共展示了Server.start方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: PyChatClient
# 需要導入模塊: import Server [as 別名]
# 或者: from Server import start [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()
示例2: len
# 需要導入模塊: import Server [as 別名]
# 或者: from Server import start [as 別名]
from functools import partial
import threading
import time
import sys
if len(sys.argv) != 2:
print "usage: python clique.py <VM password>"
sys.exit()
password = sys.argv[1]
srv1 = Server("vm12c10v01", "192.168.1.1", password)
srv1.setType("tcp")
srv1.listen("5201")
srv1.listen("5202")
srv1.listen("5203")
srv1.start("5")
srv2 = Server("vm12c11v01", "192.168.1.2", password)
srv2.setType("tcp")
srv2.listen("5201")
srv2.listen("5202")
srv2.listen("5203")
srv2.start("5")
srv3 = Server("vm12c12v01", "192.168.1.4", password)
srv3.setType("tcp")
srv3.listen("5201")
srv3.listen("5202")
srv3.listen("5203")
srv3.start("5")
示例3: PyChat
# 需要導入模塊: import Server [as 別名]
# 或者: from Server import start [as 別名]
class PyChat(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.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):
action = self.sender()
host = self.actions[action]
ip_address = socket.gethostbyname(host + '.CCPS.WAN')
self.gui = PyChatGUI(parent=self, socket_=None, ip=ip_address)
def receiveMessage(self, msg):
PyChatGUI(self, msg)
def connectToServer(self):
self.client = Client(self)
self.client.start()
self.sendSignal.connect(self.client.send_message)
self.client.message.connect(self.receiveMessage)
def send_message(self):
self.textBrowser.append(self.lineEdit.text())
self.sendSignal.emit(self.lineEdit.text())
self.lineEdit.setText('')
self.lineEdit.setFocus()
def createActions(self):
self.connectAction = QAction("&Send Message", self,
triggered=self.showDialog)
self.quitAction = QAction("&Quit", self,
triggered=qApp.quit)
self.createMoreActions()
def createMoreActions(self):
self.actions = {}
for line in open('PCs.txt'):
name, ip_address = line.split(';')
action = QAction(name, self,
triggered=self.showDialog)
self.actions[action] = ip_address.strip()
def createTrayIcon(self):
self.trayIconMenu = QMenu(self)
self.trayIconMenu.addAction(self.connectAction)
for action in self.actions:
self.trayIconMenu.addAction(action)
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(PyChat, 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()
示例4: Server
# 需要導入模塊: import Server [as 別名]
# 或者: from Server import start [as 別名]
import Server
test_server = Server() # create an instance of the Server class
test_server.start(8000) # start the server locally on any open port
示例5: enumerate
# 需要導入模塊: import Server [as 別名]
# 或者: from Server import start [as 別名]
srvmap[key] = value
# climap[key] = value
else:
climap[key] = value
# srvmap[key] = value
clients = []
servers = []
threads = []
numPairs = 2
for idx, key in enumerate(srvmap):
if idx >= numPairs: continue
srv = Server(key, srvmap[key])
srv.listen("5201")
srv.start()
servers.append(srv)
srvlist = srvmap.items()
for idx, key in enumerate(climap):
if idx >= numPairs: continue
cli = Client(key, climap[key])
cli.setTarget(srvlist[idx][1], "5201")
cli.setType("udp")
# cli.setUdpOptions("495m")
cli.setUdpOptions("495m","1400")
clients.append(cli)
print key,climap[key] + " sends to " + srvlist[idx][0],srvlist[idx][1]
for cli in clients:
thread = threading.Thread(target=partial(cli.run, 10))