开发者

Creating TCP Connections with Node.js in C++

I getting ready to write a small client module for Node.js using C++. The client will communicate with a remote server. I started by creating a class that communicates with the remote server, and I will eventually wrap that class with the main module class which inherits from node::ObjectWrap.

Typically I would use the Boost library for networking, but it dawns on me that Node has a lot of networking stuff built into it. Since开发者_开发知识库 I'm linking against Node anyway, I figure I could save myself a few dependencies by using Node's built in networking, but I can't find any documentation on Node's networking within C++.

Can anyone provide an example of using Node to create TCP connections, and send/receive data over the connection, from within C++? Or at least link to some documentation on the subject?


The node.js C++ interface is being rewritten for 0.6

Any 0.4 C++ code will break. This put's your in a painful place to do this C++ interface stuff. Basically the node.js team has written libuv that is their networking library which is an abstraction on libev & IOCP.

The best "learning" resource you can find is the libuv unit tests. You will need to test this with the latest version of 0.5.x or maybe even the master branch from the node project.

You may want to check out the tcp writealot test.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜