socket.emit vs socket.send

9,725 views
Skip to first unread message

Linus G Thiel

unread,
Jul 18, 2011, 6:28:16 AM7/18/11
to sock...@googlegroups.com
Hi,

Could someone in the know care to explain the difference between
socket.send and socket.emit, and when it's appropriate to use them?

--
Linus G Thiel
Hansson & Larsson
http://hanssonlarsson.se/
+46 709 89 03 85

Arnout Kazemier

unread,
Jul 18, 2011, 6:30:06 AM7/18/11
to sock...@googlegroups.com
socket.emit allows you to emit custom events on the server and client
socket.send sends messages which are received with the `message` event

Linus G Thiel

unread,
Jul 18, 2011, 6:30:02 AM7/18/11
to sock...@googlegroups.com
Hi,

Sorry I think I was confused. socket.send is for regular messages
right, and emit is if you want to send a particular kind of event?

Guillermo Rauch

unread,
Jul 18, 2011, 6:42:26 AM7/18/11
to sock...@googlegroups.com
Socket#send should be seen as a low-level api (for custom protocols development, or cases where maximum messages per second speed is crucial), and Socket#emit a higher-level interface (for app development).

On Mon, Jul 18, 2011 at 7:30 AM, Linus G Thiel <li...@hanssonlarsson.se> wrote:
Hi,

Sorry I think I was confused. socket.send is for regular messages
right, and emit is if you want to send a particular kind of event?

On Mon, Jul 18, 2011 at 12:28, Linus G Thiel <li...@hanssonlarsson.se> wrote:
> Hi,
>
> Could someone in the know care to explain the difference between
> socket.send and socket.emit, and when it's appropriate to use them?
>
> --
> Linus G Thiel
> Hansson & Larsson
> http://hanssonlarsson.se/
> +46 709 89 03 85
>



--
Linus G Thiel
Hansson & Larsson
http://hanssonlarsson.se/
+46 709 89 03 85



--
Guillermo Rauch
LearnBoost CTO
http://devthought.com

Linus G Thiel

unread,
Jul 18, 2011, 6:53:38 AM7/18/11
to sock...@googlegroups.com
Great, thanks!

Could you please shed some light on how namespaces work on the client side?

Do I have to do

var foo = io.connect("http://localhost/foo"),
bar = io.connect("http://localhost/bar");

Or can I utilize the same kind of api as on the server, so

var socket = io.connect();

socket.of("/foo").json.emit("qux", {foo: 1});

?

Xavier Tassin

unread,
Jul 19, 2011, 5:16:20 AM7/19/11
to sock...@googlegroups.com
Hi Guillermo,

Could you give any indication on what is the performance impact of using emit vs send?

If not, I can also benchmark it myself.

Cheers,

Xavier.

Veerabhadraiah A S

unread,
Jul 20, 2012, 8:39:11 AM7/20/12
to sock...@googlegroups.com
http://stackoverflow.com/questions/11498508/socket-emit-vs-socket-send 

On Thu, Jul 19, 2012 at 9:20 PM, Baurizio <iz...@hotmail.it> wrote:
Hi,
I'm trying to send messages from client to server, but socket.send and socket.emit not send   messages on the server console.
anyone can help me?
thanks



--
Thanks and Regards,
Veerabhadraiah A S,
Software Engineer,
Above Solutions India Pvt Ltd,
Indira Nagar,
Bangalore.



Udi Talias

unread,
Jul 20, 2012, 8:45:28 AM7/20/12
to sock...@googlegroups.com
I'm using the emit function, socket send always triggering the 'message' event on the client. With socket emit you can create events on your own and trigger them

Sent from my iPhone

方垚

unread,
Aug 2, 2012, 5:22:27 AM8/2/12
to sock...@googlegroups.com
I know diference between them.

send  is a pure text.
but emit  have event name.
e.g:
emit('eventName', message)

you can see detail on the server side

2012/7/20 Udi Talias <udi.t...@gmail.com>
Reply all
Reply to author
Forward
0 new messages