socket.io不传输给浏览器

我似乎有socket.io安装程序,并试图发出一些鸣叫,但他们没有出现在浏览器中。 这是我在控制台中得到的:

GET / 304 16ms debug - served static content /socket.io.js debug - client authorized info - handshake authorized LYlpc7dcpLyHCFcKYUJy debug - setting request GET /socket.io/1/websocket/LYlpc7dcpLyHCFcKYUJy debug - set heartbeat interval for client LYlpc7dcpLyHCFcKYUJy debug - client authorized for debug - websocket writing 1:: debug - websocket writing 5:::{"name":"tweets","args":[{"user":"AaronNewport97","text":"You're not your","latitude":51.56764399,"longitude":0.49722754}]} 51.56764399 0.49722754 

以下是来自app.js的相关代码:

 if(data.geo!=null){ latitude = data.geo.coordinates[0]; longitude = data.geo.coordinates[1]; io.sockets.volatile.emit('tweets', { user: data.user.screen_name, text: data.text, latitude: latitude, longitude: longitude }); } 

这就是我在HTML方面的:

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="/socket.io/socket.io.js"></script> <script> var socket = io.connect(); jQuery(function ($) { var tweetList = $('ul.tweets'); socket.on('tweet', function (data) { tweetList .prepend('<li>' + data.user + ': ' + data.text + '</li>'); }); }); </script> 

在巴伐利亚的控制台,我有:

 Request URL:ws://localhost:3000/socket.io/1/websocket/vBFWuusMIQbO9PeJZv8p Request Method:GET Status Code:101 Switching Protocols 

它看起来像连接正在等待。 为什么这样做?

您发送的消息被命名为tweets ,但是您的浏览器正在等待名为tweet的消息(没有-s )。

改变这一行

io.sockets.volatile.emit('tweets', {

为了这

socket.volatile.emit('tweet', {