문제

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;
}
도움이 되었습니까?

해결책 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".

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top