Calling IPV6 IP using WebSocket interface - javascript

[I've flagged this question to be deleted by moderator until I get answer to my this question]
My javascript client is working fine when talking to node.js(on Ubuntu, more here) server through WebSocket interface with IPV4 IP address.
Even though my Hosting provider is ready to allocate me IPV4, let me instead use IPV6 since there is limited supply of IPV4 now.
When using the IPV6 IP I'm getting this error:
WebSocket connection to 'ws://[2600:3c00::f03c:91ff:fe73:2b08]:31333/'
failed: Error in connection establishment:
net::ERR_ADDRESS_UNREACHABLE
I've checked that port 31333 is indeed open using tool: http://www.subnetonline.com/pages/ipv6-network-tools/online-ipv6-port-scanner.php
I've even tried solution as in IPv6 address giveing syntax error in internet explorer-10 websocket -- that is : 2600-3c00-0-0-f03c-91ff-fe73-2b08.ipv6-literal.net
I've run this client and is able to connect to the server when both are running on remote Ubuntu based server:
var WebSocket = require('ws')
, ws = new WebSocket('ws://[2600:3c00::f03c:91ff:fe73:2b08]:31333');
ws.on('open', function() {
ws.send('something');
});
ws.on('message', function(message) {
console.log('received: %s', message);
});
However when I run this same client from my home Windows 7 while the server is remote Ubuntu one, it is not able to connect:
> $ node c2.js events.js:85
> throw er; // Unhandled 'error' event
> ^ Error: connect ENETUNREACH
> at exports._errnoException (util.js:746:11)
> at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
I've even run this code in Google Chrome :
var ws = new WebSocket("ws://[2600:3c00::f03c:91ff:fe73:2b08]:31333");
ws.onerror = function(err)
{
console.log(err);
alert("Connection is error...");
};
But I get the same error:
WebSocket connection to 'ws://[2600:3c00::f03c:91ff:fe73:2b08]:31333/'
failed: Error in connection establishment:
net::ERR_ADDRESS_UNREACHABLE websocket.html:37 Event
What could be the issue?
PS: at the moment I've stopped the server at port 31333.

IPv6 is not enabled on your Realtek PCIe GBE Family Controller. If it was, there would be a line saying "Link-local IPv6 Address" in the ipconfig result.
Go to control panel > Network > Change Adapter Settings > Right click on the adapter > Properties. Check IPv6 on.

IPv6 will need to be enabled on the system, and every router between it and the ISP, and the ISP must be IPv6 ready and providing it to the end-user. The reason nslookup works is that it is just returning AAAA records, not actually connecting via IPv6. IPv4 cannot directly communicate with IPv6, or vice versa. You can't ping an IPv6 host with an IPv4 host.

Related

How to connect from browser JS to websocket server with self-signed SSL certificate?

I have an app running behind web server. Initially user loads a page via http (not https, because my http server is running on router and I need to avoid certificate warnings), then when page is loaded a websocket connection is open (wss) to the app that provides data for the web page.
It works fine, if no SSL used - http (no SSL) server + ws (no SSL) websocket.
It works fine, if I use public domain name (just for testing, not on router) with SSL (https) + wss (SSL) websocket.
But it does not work (both on local domain name or public) if SSL certificate is self-signed for websocket (not matter, http or https is used).
Tested with 2048 and 4096 bits keys.
The following code is used to connect:
try {
// var socket = new WebSocket(this.url); // This does not work, I believe because of self-signed certificate is rejected
var socket = new WebSocket(this.url, {
// protocolVersion: 8, // Tried but no difference
// origin: 'https://myserver.com:443', // Tried but no difference
rejectUnauthorized: false // This line produces an error below
})
socket.onclose = function(event) {
console.log("closed:", event.code, event.reason); // code is `1006`
})
socket.onerror = function(error) {
console.log("error:", error); // Nothing useful in this error object
})
socket.onmessage = function(event) {
console.log("data:", event.data);
})
} catch(e) {
this.error("connect error reason: " + e) // Is never called
}
Firefox error:
error: connect error reason: SyntaxError: An invalid or illegal string was specified
Chrome error:
error: connect error reason: SyntaxError: Failed to construct 'WebSocket': The subprotocol '[object Object]' is invalid.
I am able to connect to wss server using wscat (with -n option to ignore self-signed certificate error):
wscat -n -c wss://myserver.com:8443
How do I connect from browser JS to SSL websocket server with self-signed certificate?
P.S. Please keep in mind, that I will use plain http to load the web page.
UPDATE: I found this question with answer that states that parameters must be passed differently to websocket costructor:
var socket = new WebSocket(this.url, null, null, null, {rejectUnauthorized: false});
But I don't see this constructor in docs.
Though, I tried the fix and if http is used, I still get 1006 error in Chrome, but I get 1015 (TLS handshake reserved).
When using the same self-signed SSL certificate for https server and try to load the page, I get 1006 error both in Chrome and Firefox.

Websocket : Error during WebSocket handshake: Unexpected response code: 504

I have been developing a live chat that uses a websocket connection. It works fine on my localhost and on http servers. However, I am trying to get it working on a secure GoDaddy server with Deluxe Linux Hosting.
While the client is trying to open a websocket connection from javascript, it eventually responds with "WebSocket connection to 'wss://jhaubrich.com/new.projecthandle.io/Demo/include/projectChat/php-socket.php?username=Justin' failed: Error during WebSocket handshake: Unexpected response code: 504"
A 504 Gateway Timeout Error indicates an issue with the gateway or proxy server.
If I try to open the connection again without killing the PID for the lsphp, the error written to error_log by the php-socket.php file reads "PHP Warning: socket_bind(): unable to bind address [98]: Address already in use in /home/fq2cvob2t06k/public_html/new.projecthandle.io/Demo/include/projectChat/php-socket.php on line 12"
For the socket_bind() in php-socket.php I am using port 8090.
I have tried changing ports. I have tried adding 'websocket' to the end of the url in the websocket js.
//my js to initiate the websocket
var websocket = new WebSocket("ws://jhaubrich.com/new.projecthandle.io/Demo/include/projectChat/php-socket.php?username=" + userName + "" );
I expected a websocket connection to be made.
Instead I get this error : "WebSocket connection to 'wss://jhaubrich.com/new.projecthandle.io/Demo/include/projectChat/php-socket.php?username=Justin' failed: Error during WebSocket handshake: Unexpected response code: 504"
I came to the realization that I am use a shared hosting environment. I need to purchase a Virtual Private Server where I will have root privileges. Then I will be able to use WebSockets...

Websocket connection refused. WebSocket connection to 'ws://127.0.0.1:2000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

I have used websocket: https://github.com/kishor10d/CodeIgniter-Ratchet-Websocket
I have implemented websocket on a site. It is working great on localhost but when I uploaded files, it doesn't work. First there was confusion regarding the port I am using which is 2000. Now after contacting Inmotion's support they told me that 2000 is live and there are no firewall issues.
But I get this error when I reload the page:
WebSocket connection to 'ws://127.0.0.1:2000/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
According to their support there is no service listing to this port.
I have used CodeIgniter, Javascript
If you're calling the localhost (127.0.0.1) from the client app, you're calling your own computer, once you have the backend running on a remote server, you have to use the server's domain name or IP address - I'd suppose your web/server hosting service (Inmotion) assigned you the latter.

WebSocket connection to '...' failed: Invalid frame header

I use express and socket.io
My node server is running on 127.0.0.1:3000
and i have connected it
var socket = io.connect('http://127.0.0.1:3000', {query: 'id=' + user.id});
There is a warning in my browser console.
WebSocket connection to 'ws://127.0.0.1:3000/socket.io/?id=ecad7e1a009eb4f943ead0b4db8d62c4&EIO=3&transport=websocket&sid=0RMaRoZb7U67td_2AAAD' failed: Invalid frame header
Also it runs well. There is no problem :). But i wondered.
Maybe you should check versions of socket client and server. They should be the same.

MQTT 1884 connection failed

I am using mqtt for a messaging system on my site. Well on my local machine everything works fine but on my site (production) I am getting an error:
vendor.bbaf8c4….bundle.js:1 WebSocket connection to
'ws://localhost:1884/mqtt' failed: Error in connection establishment:
net::ERR_CONNECTION_REFUSED
I am using Ubuntu within my Webserver and I gave the port 1884 free.
What this error meaning?
I am using Angular4 and I add the connection within AfterViewInit
ngAfterViewInit() {
setTimeout(()=>{
this.messageservice.createMqttConnection(this.userId);
}, 200)
}
The connection with Paho on my client site looks like:
this._client = new Paho.MQTT.Client("localhost", 1884, id.toString());
Let assume my domains is mydomain.com should I replace it with localhost?
As thrashed out in the comments:
The hostname in your app needs to point to your domain e.g. mydomain.com not localhost
localhost will always point to the machine the code is running on so is very unlikely to be what you want for a production deployment of an application.

Categories

Resources