Pergunta

I use Qlocalsocket in my IPC solution and I am able to start the server and accept connections from QLocalSocket clients and communicate well, no prob in that.

but my problem happens when I kill the process of the server , I can't make QLocalServer listen on the same place again, I must change the service name to be able to start it again, which could not be possible at runtime environment.

so how to make the previous process to release that name?

here is how I start the server:

m_server = new QLocalServer(this);
if (!m_server->listen("serviceUniqueName")) {
    qDebug() << "Not able to start the Server";
    return;
}
Foi útil?

Solução 2

Qt help:

On Unix if the server crashes without closing listen will fail with AddressInUseError. To create a new server the file should be removed. On Windows two local servers can listen to the same pipe at the same time, but any connections will go to one of the server.

So, if you are using *nix, you should remove file "/tmp/socket_name".

Outras dicas

As Amartel pointed out, if the server dies, you need to delete the socket file. The best way to do is to call bool QLocalServer::removeServer ( const QString & name ):

m_server = new QLocalServer(this);
QString serverName("serviceUniqueName");
QLocalServer::removeServer(serverName);
if (!m_server->listen(serverName)) {
    qDebug() << "Not able to start the Server";
    return;
}

This way your call to listen will never fail.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top