Answer the question
In order to leave comments, you need to log in
How to receive data via websocket?
Hello! Tell me how to pull data from websocket?
The point is that it sends undefined . When creating an interval, the data comes, but it is unreasonable to get it by the interval, since the server response may be different.
function connectSocket(param, subject, method) {
var socket = new WebSocket("ws://localhost");
var id = randomId();
var dataSocket;
socket.onopen = function() {
var query = '{"id": "'+ id +'", "type": "request", "version": "v.2.0", "method": "'+ method +'", "subject": "'+ subject +'", "parameters": {'+ param +'}}';
socket.send(query);
};
socket.onclose = function(event) {
var dataSocket = 'Код: ' + event.code + ' причина: ' + event.reason;
};
socket.onmessage = function(event) {
outputSock(event.data);
};
socket.onerror = function(error) {
var dataSocket = "Ошибка " + error.message;
}
}
function outputSock(q) {
window.Sockesss = q;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question