Answer the question
In order to leave comments, you need to log in
How to fix Parse Error: Expected HTTP/?
The bottom line is this: I'm trying to make a server on a socket and connect to it from another computer, but something interferes
. Server code:
const WebSocket = require('ws');
var http = require("http");
var port = 80;
const server = http.createServer();
const wss = new WebSocket.Server({ server });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
ws.send('something');
});
server.listen(port, function(err) {
if (err) {
throw err;
}
console.log(`listening on port ${port}!`);
});
var WebSocket = require('ws')
var socket = new WebSocket("ws://75.123.130.210:80");
socket.onopen = function() {
console.log("Соединение установлено.");
};
socket.onclose = function(event) {
if (event.wasClean) {
console.log('Соединение закрыто чисто');
} else {
console.log('Обрыв соединения'); // например, "убит" процесс сервера
}
console.log('Код: ' + event.code + ' причина: ' + event.reason);
};
socket.onmessage = function(event) {
console.log("Получены данные " + event.data);
};
socket.onerror = function(error) {
console.log("Ошибка " + error.message);
};
Answer the question
In order to leave comments, you need to log in
I decided. It was about the ports. An error occurred on the VPS hosting and two people were using the same port.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question