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


Python Server.start方法代码示例

本文整理汇总了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()
开发者ID:xran-deex,项目名称:PyChat,代码行数:96,代码来源:PyChatClient.py

示例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")
开发者ID:DoctorSher,项目名称:python-iperf,代码行数:32,代码来源:clique.py

示例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()
开发者ID:xran-deex,项目名称:PyChat,代码行数:94,代码来源:PyChat.py

示例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
开发者ID:darcatron,项目名称:Networks,代码行数:6,代码来源:test_server.py

示例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))
开发者ID:DoctorSher,项目名称:python-iperf,代码行数:33,代码来源:exp.py


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