-
-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot connect to DBUS #244
Comments
Sounds like the remote end is not accepting connections. Are you able to connect to it using other utilities like 'dbus-send' or even telnet if you use TCP for connection? For me it does not look like an issue of dbus-java. I tried your example with the EmbeddedDBusDaemon of dbus-java, just works as intended:
|
Yes, when i use the dbus-send there is no problem. Can i use EmbeddedDBusDaemon for my purpose ? |
Please could you add the full source code with EmbeddedDBusDaemon ? |
EmbeddedDBusDaemon is a Java implementation of the regular dbus daemon used on most modern Linux systems. |
My tcp configuration file added as attachment. If you change its extension as conf and then run with dbus-daemon --config-file=/path/dbus-tcp.conf you can simulate my case instead of EmbeddedDBusDaemon. Thank you |
I re-run the test with different setups. Second test: using your provided config in a separate DBus instance - Wrote a small test app to export something to the second dbus instance and used your test-code to connect to the second DBus instance and call a method on the exported object retrieving a string. Also no issues:
This was my sample apps code: package com.github.hypfvieh.dbus.vmtest;
import org.freedesktop.dbus.connections.impl.DBusConnectionBuilder;
import org.freedesktop.dbus.interfaces.DBusInterface;
import java.time.LocalDateTime;
public class VMTestApp {
public static void main(String[] args) {
try (var con = DBusConnectionBuilder.forAddress("tcp:host=127.0.0.1,port=2334").build()) {
QueryTestClz queryTestClz = new QueryTestClz();
con.requestBusName(VMTestApp.class.getPackageName());
con.exportObject(queryTestClz);
while (true) {
Thread.sleep(1000);
}
} catch (Exception _ex) {
_ex.printStackTrace();
}
}
public interface QueryTest extends DBusInterface {
String doQueryTest();
}
public static class QueryTestClz implements QueryTest {
private int callCounter = 0;
@Override
public String getObjectPath() {
return "/vmtest";
}
@Override
public String doQueryTest() {
String str = "You are connected to %s, connect number: %d".formatted(getHostName(), ++callCounter);
System.out.println("[" + LocalDateTime.now() + "] " + str);
return str;
}
static String getHostName() {
try {
return java.net.InetAddress.getLocalHost().getHostName();
} catch (java.net.UnknownHostException _ex) {
return "unknown host name";
}
}
}
} |
But i stop the dbus daemon after connection is established then my code try to reconnect and print "No connection to DBUS". After this line printed i run the dbus daemon again but no connection is established in client side so always print "No connection to DBUS". I didnt see no connection line in your side. Did you stop the dbus daemon when client code is running ? |
…mon disconnected before This issue is triggered when shared connections are enabled (default) and you create a connection to a DBus daemon, then the daemon is restarted (process killed and restarted) causing your connection to be closed. When retrying to connect to the restarted DBus Daemon the shared-feature will try to reuse the existing connection even though the underlying transport already disconnected. This patch will check the transport connection status on shared connections before re-using them. If the transport is closed/broken the stored connection reference will be removed and a new connection is created. Otherwise if transport is still ok, the same connection is returned (like before).
This stopping of the daemon makes the difference. This is in deed a problem in dbus-java when using shared connections (which is the default). I fixed that issue right now. Now when shared connections are enabled the transport status is checked before a existing connection will be re-used. If the transport is dead already, the connection object is dropped and a new one will be created. |
Thank you for the quick response and fix. But how can i use this updated version ? Normally i use 4.3.1 version in my project which is developed in java 11. I think you updated the current one and it requires java 17, am i right ? |
Correct it is only fixed in 5.0.0-SNAPSHOT. If you need to stick to Java 11, you may disable shared connections: |
Thank you so much |
I connect to a remote DBUS device and control the media player. For this, I wrote a test code as follows. Here, a DBUS connection is created every 10 seconds in an endless loop. Then it is checked whether the dbus connection exists and after 7 seconds the dbus connection is closed. The problem here is that when you connect to dbus for the first time, if the remote dbus is terminated and started again, the dbus connection is not established and it says No connection. Test code is below.
Output
Connected to DBUS
Disconnected from DBUS
No connection to DBUS
Disconnected from DBUS
No connection to DBUS
Disconnected from DBUS
The text was updated successfully, but these errors were encountered: