wrslatz
wrslatz

Reputation: 422

Javascript Vert.x EventBus Client SockJS get host and port of connection

I am using Vert.x Core 3.3.3 and Web 3.3.3 in Java as an EventBus server and Vert.x 2.0.0 and SockJS 1.1.1 on a web client in Javascript to connect to the EventBus. I am connected, able to send and receive messages, and all inbound and outbound traffic is open. Everything is functioning properly.

My server is able to get the host and port for each EventBus connection when the client connects. This comes from the SockJSHandler's bridge event in Java, via socket().remoteAddress() in the format "host:port".

On the web client side, is there functionality to get the remote address (host and port of the server) of the EventBus SockJS connection to my Vert.x Server's EventBus? I have looked in the documentation for Vert.x Web Client (http://vertx.io/docs/jsdoc/ & https://github.com/vert-x3/vertx-web) but have not found anything useful.

If you need more info please let me know. Thanks in advance.

EDIT 1:

I misunderstood what I was actually looking for in my original question and phrased it poorly. I know what the host and port of the EventBus are when I make the connection (i.e. var eb = new EventBus('localhost:8080/eventbus'); as @Paulo said).

What I am actually looking for is the host and port for the Handler that my client registers on that EventBus. I can see this on the server side as mentioned above. The host comes back as an ip address, not what I passed in to create the EventBus connection on the client-side. And the port is different, because a new SockJS connection is made for that handler (?). Is it possible to get the host and port, especially port, of the SockJS connection for my client's Handler.

Upvotes: 1

Views: 878

Answers (1)

Paulo Lopes
Paulo Lopes

Reputation: 5801

The information you want to have is something you already know. When you create a eventbus connection from your client web application you do:

var eb = new EventBus('http://localhost:8080/eventbus');

As you can see the parameter you must pass to the constructor contains what you want to know:

localhost:8080

Most of the times you do not want to use an hardcoded hostname + port but the location where your html has been served so in JavaScript you can just do:

window.location.host

And that will give you the location where your server is running.

Upvotes: 2

Related Questions