Hello,
After many time on NodeJS, I'd just discovered Vert.x 2 days ago.
I just wrote a small websocket test. When I precise the exact port in the client (ex: "ws://myweb.site:8080") this works perfectly.
But when I use NginX redirection from ":80/server" to " :8080/server" the connection works but the socket disconnect after 1 minute.
( The reason of this redirect is to bypass firewall problem, to permit the client to only use the standard 80 port. )
I precise the same example under NodeJS doesn't have this disconnect problem.
Here is the NginX configuration :
location /server {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:8080;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
Here is the client script :
<script>
var socket = new WebSocket("ws://myweb.site:8080"); // Works perfectly
// var socket = new WebSocket("ws://myweb.site/server"); // Works but disconnect after 1 minute
socket.onmessage = function(event) {
alert("Received data from websocket: ");
}
socket.onopen = function(event) {
alert("Web Socket opened");
socket.send("Hello World");
};
socket.onclose = function(event) {
alert("Web Socket closed");
};
</script>
Here is the Vert.x verticle :
var vertx = require('vertx');
var console = require('vertx/console');
var server = vertx.createHttpServer();
server.websocketHandler(serverConnection);
server.listen(8080, '0.0.0.0');
function serverConnection(client)
{
console.log('New connection: ' + client.path());
client.write(new vertx.Buffer('Welcome!'));
}
Any help would be appreciated :)
Regards,