javascript - socket.io client hangs up -
using socket.io client hangs (page keeps loading) on posting form - stopping node server client runs fine again instantly.
server
app.post('/', function(req, res) { io.sockets.emit('messages', { user: req.body.user, message: req.body.message }); });
client
<script src="socket.io.js"></script> <script> var socket = io.connect('http://localhost:3000'); socket.on('messages', function (data) { console.log(data); $('.entry').first().before( '<div class="entry well-large">' + data.user + ' says: ' + data.message + '</div>'); });
you should end http request, you're not doing in post
handler. if don't, express won't return answer browser , browser keep waiting 1 (until @ point gets tired of waiting , generates timeout).
try instead:
app.post('/', function(req, res) { io.sockets.emit('messages', { user: req.body.user, message: req.body.message }); // end request ending response res.end(); });
(it's not enough send message socket.io
, because that's separate protocol)
Comments
Post a Comment