コード例 #1
0
    def __init__(self, port, directory_tree, parent=None):
        super().__init__(parent)
        self.port = int(port)
        self.directory_tree = directory_tree
        self.server = QtNetwork.QTcpServer(self)

        self.server.newConnection.connect(self._handle_new_connection)
        self.server.acceptError.connect(self._handle_accept_error)
        vstreamer_utils.log_info("Initialized communication server")
コード例 #2
0
    def set_this_device(self):
        addresses = QtNetwork.QNetworkInterface.allAddresses()
        for address in addresses:
            if not (address.isLinkLocal() or address.isBroadcast()
                    or address.isMulticast() or address.isLoopback()
                    or address.protocol()
                    == QtNetwork.QAbstractSocket.IPv6Protocol):
                self._ip_address = address
        info = QtNetwork.QHostInfo()
        self._name = info.localHostName()
        self._server = QtNetwork.QTcpServer()

        self._server.setSocketDescriptor(self._socket.socketDescriptor())
        self._server.listen(self._ip_address, Setup().get_port())
        self._server.newConnection.connect(self.receive)
コード例 #3
0
    def __init__(self, parent=None):
        super(Server, self).__init__(parent)

        statusLabel = QtWidgets.QLabel()
        quitButton = QtWidgets.QPushButton("Quit")
        quitButton.setAutoDefault(False)

        self.tcpServer = QtNetwork.QTcpServer(self)
        if not self.tcpServer.listen():
            QtWidgets.QMessageBox.critical(
                self, "Fortune Server", "Unable to start the server: %s." %
                self.tcpServer.errorString())
            self.close()
            return

        statusLabel.setText("The server is running on port %d.\nRun the "
                            "Fortune Client example now." %
                            self.tcpServer.serverPort())

        self.fortunes = (
            "You've been leading a dog's life. Stay off the furniture.",
            "You've got to think about tomorrow.",
            "You will be surprised by a loud noise.",
            "You will feel hungry again in another hour.",
            "You might have mail.",
            "You cannot kill time without injuring eternity.",
            "Computers are not intelligent. They only think they are.")

        quitButton.clicked.connect(self.close)
        self.tcpServer.newConnection.connect(self.sendFortune)

        buttonLayout = QtWidgets.QHBoxLayout()
        buttonLayout.addStretch(1)
        buttonLayout.addWidget(quitButton)
        buttonLayout.addStretch(1)

        mainLayout = QtWidgets.QVBoxLayout()
        mainLayout.addWidget(statusLabel)
        mainLayout.addLayout(buttonLayout)
        self.setLayout(mainLayout)

        self.setWindowTitle("Fortune Server")
コード例 #4
0
    def __init__(self, parent=None):
        super(Dialog, self).__init__(parent)

        self.tcpServer = QtNetwork.QTcpServer()
        self.tcpClient = QtNetwork.QTcpSocket()
        self.bytesToWrite = 0
        self.bytesWritten = 0
        self.bytesReceived = 0

        self.clientProgressBar = QtGui.QProgressBar()
        self.clientStatusLabel = QtGui.QLabel("Client ready")
        self.serverProgressBar = QtGui.QProgressBar()
        self.serverStatusLabel = QtGui.QLabel("Server ready")

        self.startButton = QtGui.QPushButton("&Start")
        self.quitButton = QtGui.QPushButton("&Quit")

        buttonBox = QtGui.QDialogButtonBox()
        buttonBox.addButton(self.startButton,
                            QtGui.QDialogButtonBox.ActionRole)
        buttonBox.addButton(self.quitButton, QtGui.QDialogButtonBox.RejectRole)

        self.startButton.clicked.connect(self.start)
        self.quitButton.clicked.connect(self.close)
        self.tcpServer.newConnection.connect(self.acceptConnection)
        self.tcpClient.connected.connect(self.startTransfer)
        self.tcpClient.bytesWritten.connect(self.updateClientProgress)
        self.tcpClient.error.connect(self.displayError)

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.addWidget(self.clientProgressBar)
        mainLayout.addWidget(self.clientStatusLabel)
        mainLayout.addWidget(self.serverProgressBar)
        mainLayout.addWidget(self.serverStatusLabel)
        mainLayout.addStretch(1)
        mainLayout.addSpacing(10)
        mainLayout.addWidget(buttonBox)
        self.setLayout(mainLayout)

        self.setWindowTitle("Loopback")