Node.js emit not working on specific socket.on -


i'm trying send news client. on connect, works great, reason on broadcast2 wont response client sided, know same piece of code, , broadcast2's console.log working.

q: how can make sure broadcast2 emit work?

this works:

socket.on('message', function (data) {   console.log('message gotten');   socket.emit('news', { message: 'xxxx' }); }); 

this wont work:

socket.on('broadcast2', function (data) {   console.log("broadcast revieced");   socket.emit('news', { message: 'xxxx' }); }); 

this node.js response:

enter image description here

total code in node.js

socket.on('message', function (data) {   console.log('message gotten'); });  socket.on('another-message', function (data) {   socket.emit('not-news', { hello: 'world' }); });   socket.on('broadcast2', function (data) {   console.log("broadcast revieced");   socket.emit('news', { message: 'xxxx' }); }); 

and on client side:

var socket = io.connect('mysite:8080');  function sender() {   console.log('sending tester');   socket.emit('sendertester', 2); }  socket.on('connect',function(){  });    socket.on('tester', function(msg){   console.log("callback"); });  socket.on('news', function(message) {   console.log("incomming news");   console.log(message); }); 

update 1:

the broadcast2 socket, sent php:

function broadcast($message,$broadcast = 'broadcast2') {   $client = new client(new version1x('myurlhidden:8080'));    $client->initialize();   $client->emit($broadcast, ['message' => $message]);   $client->close(); } 

update 2:

**question two: cause broadcast2 sent before client sided loaded, , client connects node, cause?

but in same time, im preloading class holds broadcast2 emitter.

using codeigniter framework.**

update 3

i trying check theory on update 2, having 2 users logged in, while user 1 trying perform trigger. user 2 gets no output, suppose theory busted.

the server cannot send message socket before connected. have wait until have listening receive sending.

i wouldn't call close after emit either, may close connection before client has received message, emit doesn't wait client receive data before returning asynchronous.

instead let clients close connections when terminate.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -