Answer the question
In order to leave comments, you need to log in
How to connect to the server in websockets (socket.io)?
I have a Heroku site and I know my IP. The server is running on my PC. How to connect socket.io on a website to it?
<script src="/socket.io/socket.io.js"></script>
<script>
let socket = io(); // может тут надо написать? если да, то как примерно должно выглядеть?
Answer the question
In order to leave comments, you need to log in
On the client. the url at which the socket is available, usually in the form ip:port or domain:port; port is usually 3000, but can be anything. It is not necessary to send an object, it is enough to track the events transmitted to emit as the first parameter. The syntax for emit and on is the same on the server and client.
var socket_url = "yoursite.ru:3000";
var socket = io.connect (socket_url);
// Отправка чего-то на сервер
socket.emit ('Privet',
{
param1: 'kaknikruti',
param2: 12345
// и так далее
});
// Приём с сервера
socket.on ('Otvet', function (data)
{
alert (data.otvet);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question