i have one issue with node module - websocket, yesterday all worked good, but today, after i run node, i see just one message in browser "Upgrade Required". this my code:
// first file ws.js:
var WebSocketServer = require("ws").Server;
var wss = new WebSocketServer({ port: 9000 });
wss.on("connection", function(ws){
ws.send("Welcome to cyber chat");
});
// seccond file ws-client.js
var ws = new WebSocket("ws://localhost:9000");
ws.onopen = () => {
setTitle("Connected to Cyber Chat");
};
ws.onclose = () => {
setTitle("DISCONNECTED");
};
ws.onmessage = payload => {
printMessage(payload.data);
};
document.forms[0].onsubmit = function() {
var input = document.getElementById('message');
input.value = '';
};
function setTitle(title) {
document.querySelector('h1').innerHTML = title;
}
function printMessage(message) {
var p = document.createElement('p');
p.innerText = message;
document.querySelector('div.messages').appendChild(p);
}
i have seen so much same problems, and not just here, on this site, but not find normally short and correct answer, or just long answer, but step by step.
via John Smith
No comments:
Post a Comment