Reputation: 45692
How can I connect Cex.IO websocket API from my Java verticles?
The problem is that Vert.x doesn't provide me with a way to connect only with WsURI as Node.JS does. I have to specify port and host and get HTTP 400 Bad Request exception.
With Node.js you do:
var WebSocketClient = require('websocket').client;
var client = new WebSocketClient();
client.connect("wss://ws.cex.io/ws/");
With Vert.x you have to do
int host = 443; // That's defaults
String host = "cex.io"; // Am I right by specifying this host?
HttpClient client = Vertx.vertx().createHttpClient();
client.websocket(port, host, "wss://ws.cex.io/ws/", ws -> { ...});
Upvotes: 1
Views: 1119
Reputation: 9128
This HttpClient#websocket method takes a relative URI as third parameter.
You should be able to connect like this:
client = vertx.createHttpClient(new HttpClientOptions()
.setDefaultHost("ws.cex.io")
.setDefaultPort(443)
.setSsl(true));
client.websocket("/ws", ws -> {
// Work with the websocket
});
Upvotes: 6