Answer the question
In order to leave comments, you need to log in
Why doesn't WebSocket connect to the server?
Actually there is a server on SockJS, when connecting, the client tells me that: WebSocket is closed before the connection is established. And although everything works fine with Loong Poling, I would like to connect via WebSocket because the delay is critical in this case.
Server code:
var http = require('http'),
connect = require('connect'),
sockjs = require('sockjs'),
...
var app = connect()
.use(connect.static('./client'));
var server = http.createServer(app);
var echo = sockjs.createServer({
log: function(severity, line) {
return log.log(severity, line);
},
websocket: true
});
echo.installHandlers(server, {
prefix:'/socket-server'
});
echo.on('connection', function(conn) {
...
});
server.listen(config.get('port'));
var sock = new SockJS('http://localhost:1000/socket-server');
...
Answer the question
In order to leave comments, you need to log in
Here you need to study the issue with sockets. The fact is that Loong Poling works over the http protocol, so everything is ok. Web sockets send a request using the ws protocol. those. instead of address localhost:1000/socket-server, it should be ws://localhost:1000/socket-server
Better look at a href=" learn.javascript.ru/nodejs-screencast ">Ilya Kontor's Node js lessons. More specifically Part 2, Lesson 10.
As I understand it, you made a socket client. You need to create a socket server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question