S
S
SmokingElk2021-04-25 14:59:10
JavaScript
SmokingElk, 2021-04-25 14:59:10

How to connect to WS server using hamachi?

I'm trying to organize a node.js WebSocket server (not big, for a couple of devices). I don't want to pay for a white IP, even more so for a VPN. I decided to try to combine devices using a program to create a small VPN for several hamachi devices. For the server, I use the ws module. The code

const WebSocket = require("ws");
const port = 9100;
const server = new WebSocket.Server({port: port});

const onConnect = client => {
    console.log("Connection!"); 
    client.send('Connection!');

    const onMsg = msgStr => {
        try {
            client.send(msgStr);
        } catch (e) {
            console.error(e);
        }
    };

    client.on("message", onMsg);

    client.on("close", () => console.log("User disconnect!"));
};

server.on("connection", onConnect);

console.log("Сервер запущен на порту: " + port);


In hamachi, I created a network, started the server, opened the port (via torrent). Copied IPv4 from hamachi. I tried to connect from my computer (the address entered " ws://IPv4:9100 "). Doesn't work, throws an error WebSocket connection to ' ws://IPv4:9100/ ' failed. I don’t really understand this, so it’s very difficult to understand the reason for it myself. Who knows, tell me: what can be done?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question