У меня есть следующий код на моем сервере
var socket = require( 'socket.io' );
var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = socket.listen( server );
var port = process.env.PORT || 3000;
server.listen(port, function () {
console.log('Server listening at port %d', port);
});
io.on('connection', function (socket) {
socket.on( 'new_count_message', function( data ) {
io.sockets.emit( 'new_count_message', {
new_count_message: data.new_count_message
});
});
socket.on( 'update_count_message', function( data ) {
io.sockets.emit( 'update_count_message', {
update_count_message: data.update_count_message
});
});
socket.on( 'new_message', function( data ) {
io.sockets.emit( 'new_message', {
name: data.name,
email: data.email,
subject: data.subject,
created_at: data.created_at,
id: data.id
});
});
});
Но вместо того, чтобы показывать в консоли «update_count_message», консоль записывает непрерывный поток опросов.
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850081140-15
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850080247-12
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850080252-13
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850081252-16
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850081290-17
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850081351-18
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850081416-19
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850081474-20
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850081532-21
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850081576-22
GET http://localhost/socket.io/?EIO=3&transport=polling&t=1448850081651-23
как я могу это решить? Я не хочу получать петлю в браузере.
var socket = io.connect('http://localhost:3000')
30.11.2015http://localhost:80
, а не кhttp://locahost:3000
, поэтому он никогда не подключается к NodeJS и входит в бесконечный цикл. 30.11.2015io.connect('http://localhost:3000')
30.11.2015