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