Trojan Trojan - 1 year ago 133
Node.js Question

Send a message to specific people including sender using in nodejs

How to send a message to particular client including sender..

The following is the code i used to send a message to particular client.

socket.on('chat message', function(msg){'chat message', msg);

Ofcourse its working But it just sending to the client(reciever) only.But i want to send a message to particular client(reciever) including sender also.

Is anything need to add in that code.?? suggestions are welcome.!!


Answer Source

There are 2 ways to achieve same from server end

1) Emit event to both user separately 2) Broadcast event to array of user(In your case senderId, reciverId)

Here i am enclosing broadcast function considering you are already aware with emit.'eventName', {
                data: "somedata"

Here, arrayOfIds : Array of Id of Recivers, i.e.(Id Of sender and Id Of receiver)

This function with send event to both user, including sender him self.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download