node.js - client is not receiving message from server but server is receiving from client. Using express and socket.io -
server.js file:-------------------------------------------------- var app = require('express')(); var server = require('http').server(app); var io = require('socket.io')(server); server.listen(8001); app.get('/', function (req, res) { res.sendfile(__dirname + '/client.html'); }); io.on('connection', function (socket) { socket.emit('news', 'i server'); socket.on('my other event', function (data) { console.log(data); }); }); client.html:---------------------------------------------------- var socket = io.connect('http://localhost:8001'); socket.on('news', function (data) { console.log(data); }); socket.emit('my other event', 'i client');
now when load page http://localhost:8001, terminal shows message - 'i client'. not show message received server.
Comments
Post a Comment