Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Creating TCP Connections with Node.js in C++

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?

Problem courtesy of: mellowsoon


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.

Solution courtesy of: Raynos


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Creating TCP Connections with Node.js in C++


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription