Answer the question
In order to leave comments, you need to log in
How to work with sockjs?
Good afternoon!
I want to understand the work of node.js + sockjs.
I start the server:
var http = require('http');
var $server = 'test.lan';
if (http) {
var sockjs = require('sockjs');
var echo = sockjs.createServer();
echo.on('connection', function(conn) {
conn.on('data', function(data_id) {
conn.write(data_id);
});
conn.on('close', function() {});
});
var server = http.createServer();
echo.installHandlers(server, {prefix:'/echo'});
server.listen(5555, $server);
}
var sock = new SockJS('http://test.lan:5555/echo');
sock.onopen = function() {
console.log('open');
};
sock.onmessage = function(e) {
console.log('result data: ', e.data);
};
sock.onclose = function() {
console.log('close');
};
// отправляем данные
setInterval(function() { sock.send(40); }, 1000);
sock.send(40);
conn.on('data', function(data_id) {
// что делать дальше?
});
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