I'm completely new to web sockets and javascript. I'm trying to create a chat application using javascript and socket.io. It works on localhost (using "npm start" command line).
My question is: how can I access it from any other PC and use it like a real chat application?
I have the following error when I don't access it on localhost:
How can I host it for free and access it from anywhere? Can someone provide me an example of a socket.io chat application and step-by-step instructions?
It does not work because if you are accessing to your website not from localhost, your hostname will not be the server address. So, in your var socket = io(); you can specify the url that the user is accessing your website from.
Like this:
// get the url
let url = window.location.href.split("/");
url = url[0] + "//" + url[2];
const socket = io(url);