rpcSocket.addMessageHandler(this);
initialized = true;
} else {
- logger.debug("{}: Disconnect Rpc Socket on initialize", thingName);
- disconnect();
+ if (rpcSocket.isConnected()) {
+ logger.debug("{}: Disconnect Rpc Socket on initialize", thingName);
+ disconnect();
+ }
}
}
}
private void disconnect() {
- rpcSocket.disconnect();
+ if (rpcSocket.isConnected()) {
+ rpcSocket.disconnect();
+ }
}
public Shelly2RpctInterface getRpcHandler() {
s.close(StatusCode.NORMAL, "Socket closed");
session = null;
}
- client.stop();
+ if (client.isStarted()) {
+ client.stop();
+ }
} catch (Exception e) {
if (e.getCause() instanceof InterruptedException) {
logger.debug("{}: Unable to close socket - interrupted", thingName); // e.g. device was rebooted