Autobahn|Java - Instant disconnect when attempting to connect (both on Android as well as on a PC)

62 views
Skip to first unread message

Luka Miljak

unread,
Aug 2, 2018, 7:22:59 AM8/2/18
to Autobahn
The problem I get is very simple, yet the cause remains unknown to me. The following code does not seem to work:

import io.crossbar.autobahn.wamp.Client;
import io.crossbar.autobahn.wamp.Session;
import io.crossbar.autobahn.wamp.types.ExitInfo;

import java.util.concurrent.CompletableFuture;

public class Main {

public static void main(String[] args) {

final String url = "ws://localhost:8080";
final String realm = "realm";

Session session = new Session();

session.addOnJoinListener((ses, details) -> System.out.println("Joined"));
session.addOnDisconnectListener((ses, clean) -> System.out.println("Disconnected"));
session.addOnLeaveListener((ses, clean) -> System.out.println("Left"));
session.addOnConnectListener((ses) -> System.out.println("Connected"));

Client client = new Client(session, url, realm);

CompletableFuture<ExitInfo> connection = client.connect();
connection.join();
System.out.println("Exiting");
}
}

The dependency I included in my pom.xml is as follows:
<dependency>
<groupId>io.crossbar.autobahn</groupId>
<artifactId>autobahn-java</artifactId>
<version>18.5.1</version>
</dependency>

When running this code, my console logs are:

Aug 02, 2018 1:16:59 PM io.crossbar.autobahn.wamp.transports.NettyWebSocketClientHandler
INFO: WebSocket Client disconnected!
Left
Disconnected
Exiting

At this point, the program has not terminated yet. Meaning that there still must be some unknown Thread running in the background.
Furthermore, if I try to connect to the router using Autobahn|JS, it works just fine.

The Crossbar router does not give any logs whatsoever. However, attempting using the Go Nexus Router, I get the following log: "Error attaching to router: did not receive HELLO: receive channel closed"

Some help with this problem would be appreciated.


Omer Akram

unread,
Aug 2, 2018, 9:05:40 AM8/2/18
to Autobahn
Hi!
This is unrelated to autobahn, rather the way java's async programming works so to fix it, instead of connect.join() do connection.get() and your program should work.

Luka Miljak

unread,
Aug 2, 2018, 9:21:23 AM8/2/18
to Autobahn
Hmm, I've replaced my connection.join() with the following code:
try {
connection.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
and I still get the exact same logs. Getting anything different would be strange as I thought that future.join() does the same as future.get() with the difference that "join" throws unchecked exceptions and "get" throws checked exceptions, requiring you to surround it by a try-catch block.
Furthermore, I've also tried using a callback as such:
connection.thenAccept(exitInfo -> {
System.out.println("Exiting");
});
new Scanner(System.in).nextLine();
which also gives me the same result. (I added the Scanner line to wait for a newline, as the program immediately terminates if that doesn't happen.

Tobias Oberstein

unread,
Aug 3, 2018, 2:03:01 AM8/3/18
to autob...@googlegroups.com, Luka Miljak
Hi,


>>> Some help with this problem would be appreciated.

as mentioned, your problems are async programming related, not
autobahn-java .. I would read a little into Java 8 and Future etc

also, try our getting started

https://github.com/crossbario/autobahn-java#getting-started

and move from there ..

cheers,
/Tobias

Omer Akram

unread,
Aug 3, 2018, 4:49:38 AM8/3/18
to Autobahn
One suggestion, your url should be as below (not the trailing /ws) and please make sure your realm name refers to whats configured in Crossbar config.
ws://localhost:8080/ws
Reply all
Reply to author
Forward
0 new messages