I' m new to WebSocket and Node.js. I'm trying to create a real-time chat as a basic program. I basically based my code here. I run my code in Amazon Linux for it to run as a real web server. I always got an error after I input the user's name.
I use node-static as a static server API for my index.html file.
Here's my code for my javascript: app.js And here's my code for index.html located inside the "public" folder: index.html I always get the error at line15 in index.html.
Can anyone tell me what is the problem there? I tried moving that part anywhere inside the connectToChat() function but the error is still there.
You have an error in url you call. It have to be
ws://<mywebserver>:8000instead ofws://<mywebserver>:8000/index.htmlTo fix it, in index.html , change this line
var url = document.URL.replace("http://", "ws://");tovar url = document.origin.replace("http://", "ws://");