Maybe you can consider socket.io, which handle most of the things for you.
Here is an example:
http://fbwebsocket.nodester.com/
http://socket.io/
Thanks and Regards,
Sky
Tim Caswell <[email protected]> 於 2012/5/28 下午11:41 寫道:
> This is a common problem porting blocking code to node. If you block on
> network sockets in node, it will destroy the performance of your server.
> There is only one thread. The server will be unable to serve multiple
> connections at once if one is blocking.
>
> Why are you porting this to node? This requirement is fundamentally
> incompatible with the design of node. If you want the awesome concurrent
> socket performance capabilities of node, this is only done by never using
> blocking I/O.
>
> So assuming you want to port to node anyway, the code's structure will have
> to be modified to accommodate for the async requirements of node.
> (Technically you could modify node through a C addon to have multiple threads
> and block the thread, but that's not going to scale near as well as a single
> thread using non-blocking code due to the high cost of thread context
> switching and thread syncing)
>
> On Mon, May 28, 2012 at 5:02 AM, Oleg Podsechin <[email protected]>
> wrote:
> as an example of what i have:
>
> var socket = new SocketSync();
> socket.open('localhost', 8856);
> socket.write('my request');
> var mydata= socket.read();
> socket.end();
>
> Check out the "socket" module in Common Node:
> https://github.com/olegp/common-node
>
> Here's the canonical chat example written using the lib:
> https://github.com/olegp/common-node/blob/master/examples/chat.js
>
> In your code above, "SocketSync" becomes "Socket" and "open" becomes
> "connect". Everything else should work as is.
>
> Oleg
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en