예제 #1
0
def init():
    """Start listening to incoming connections."""
    global _server
    if _server is not None:
        return
    
    server = QLocalServer(None)
    
    # find a free socket name to use
    for name in ids():
        if server.listen(name):
            break
    else:
        # all names failed, try to contact and remove stale file if that fails
        socket = QLocalSocket()
        for name in ids():
            socket.connectToServer(name)
            if not socket.waitForConnected(10000):
                QLocalServer.removeServer(name)
                if server.listen(name):
                    break
            else:
                socket.disconnectFromServer()
        else:
            # no ids left, dont listen
            return
    app.aboutToQuit.connect(server.close)
    server.newConnection.connect(slot_new_connection)
    os.environ["FRESCOBALDI_SOCKET"] = ensure_bytes(name)
    _server = server
예제 #2
0
def init():
    """Start listening to incoming connections."""
    global _server
    if _server is not None:
        return

    server = QLocalServer(None)

    # find a free socket name to use
    for name in ids():
        if server.listen(name):
            break
    else:
        # all names failed, try to contact and remove stale file if that fails
        socket = QLocalSocket()
        for name in ids():
            socket.connectToServer(name)
            if not socket.waitForConnected(10000):
                QLocalServer.removeServer(name)
                if server.listen(name):
                    break
            else:
                socket.disconnectFromServer()
        else:
            # no ids left, don't listen
            return
    app.aboutToQuit.connect(server.close)
    server.newConnection.connect(slot_new_connection)
    os.environ["FRESCOBALDI_SOCKET"] = name
    _server = server
예제 #3
0
    def __isServerRun(self, servername):  # 判断是否有一个同名的服务器在运行
        #  用一个localsocket去连一下,
        #  如果能连上就说明 有一个在运行了
        ls = QLocalSocket()

        ls.connectToServer(servername)
        if (ls.waitForConnected(1000)):
            ls.disconnectFromServer()  # // 说明已经在运行了
            ls.close()
            return  True
        return False
예제 #4
0
 def send_message(self, message):
     if not self.is_running:
         raise Exception("Client cannot connect to IPC server. Not running.")
     socket = QLocalSocket(self)
     socket.connectToServer(self.socket_filename, QIODevice.WriteOnly)
     if not socket.waitForConnected(self.timeout):
         raise Exception(str(socket.errorString()))
     socket.write(pickle.dumps(message))
     if not socket.waitForBytesWritten(self.timeout):
         raise Exception(str(socket.errorString()))
     socket.disconnectFromServer()
예제 #5
0
    def __isServerRun(self, servername):  # 判断是否有一个同名的服务器在运行
        #  用一个localsocket去连一下,
        #  如果能连上就说明 有一个在运行了
        ls = QLocalSocket()

        ls.connectToServer(servername)
        if (ls.waitForConnected(1000)):
            ls.disconnectFromServer()  # // 说明已经在运行了
            ls.close()
            return True
        return False
예제 #6
0
 def send_message(self, message):
     if not self.is_running:
         raise Exception(
             "Client cannot connect to IPC server. Not running.")
     socket = QLocalSocket(self)
     socket.connectToServer(self.socket_filename, QIODevice.WriteOnly)
     if not socket.waitForConnected(self.timeout):
         raise Exception(str(socket.errorString()))
     socket.write(pickle.dumps(message))
     if not socket.waitForBytesWritten(self.timeout):
         raise Exception(str(socket.errorString()))
     socket.disconnectFromServer()
예제 #7
0
    def sendMessage(self, message):
        assert(self._isRunning)

        if self.isRunning():
            socket = QLocalSocket(self)
            socket.connectToServer(self._key, QIODevice.WriteOnly)
            if not socket.waitForConnected(self._timeout):
                return False
            socket.write(message.encode('utf-8'))
            if not socket.waitForBytesWritten(self._timeout):
                return False
            socket.disconnectFromServer()
            return True
        return False
예제 #8
0
    def sendMessage(self, message):
        assert (self._isRunning)

        if self.isRunning():
            socket = QLocalSocket(self)
            socket.connectToServer(self._key, QIODevice.WriteOnly)
            if not socket.waitForConnected(self._timeout):
                return False
            socket.write(message.encode('utf-8'))
            if not socket.waitForBytesWritten(self._timeout):
                return False
            socket.disconnectFromServer()
            return True
        return False