1

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?

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for all the info. I'm writing a Node module in C++ for the learning experience, so the up coming API change isn't a huge deal for me.
@mellowsoon I would recommend you a) check those tests work, and be go ask the guys in #node on freenode that using libuv is sensible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.