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
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
def __isServerRun(self, servername): # 判断是否有一个同名的服务器在运行 # 用一个localsocket去连一下, # 如果能连上就说明 有一个在运行了 ls = QLocalSocket() ls.connectToServer(servername) if (ls.waitForConnected(1000)): ls.disconnectFromServer() # // 说明已经在运行了 ls.close() return True return False
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()
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()
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
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