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

#1

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:

io.crossbar.autobahn autobahn-java 18.5.1 ``` ```

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.

0 Likes

#2

Hi!

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

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.

···

On Thursday, August 2, 2018 at 4:22:59 PM UTC+5, Luka Miljak wrote:


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.

0 Likes

#3

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.

···

On Thursday, 2 August 2018 15:05:40 UTC+2, Omer Akram wrote:

Hi!

On Thursday, August 2, 2018 at 4:22:59 PM UTC+5, Luka Miljak wrote:

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

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.


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.

0 Likes

#4

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

0 Likes

#5

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


<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

On Thursday, August 2, 2018 at 6:21:23 PM UTC+5, Luka Miljak wrote:
> 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.

> 
> 
> On Thursday, 2 August 2018 15:05:40 UTC+2, Omer Akram wrote:
> > Hi!
> > 
> > On Thursday, August 2, 2018 at 4:22:59 PM UTC+5, Luka Miljak wrote:
> > > 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

> > 

> > 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.

> > > ```
> > > 

> > > 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.

> > > 

> > >

</details>
0 Likes