Using NetworkTables in C++ (need a quick and concise tutorial)

Disclaimer: I have only been programming for a little over a year, so I am still somewhat of an amateur.

My team is thinking of using our driver station to do image processing and sending data to and from the robot. I did some digging around and learned about WPILib’s NetworkTable, and I heard about how simple it is to use. However, I’m having some trouble finding sufficient documentation to learn how to use NetworkTable. This is the only thing I could find:

However, the most crucial part of the documentation (“The client (laptop) side of the program”) is written in Java, which I have been unable to successfully translate into C++. Do any of you know where I could find similar documentation on NetworkTable, specifically for C++? If not, could anyone sort of summarize how it should be used and provide examples in C++? Thank you!

We only supplied a Java desktop version of NetworkTables. Is it possible that you can use that for your application? The problem was that the Windows networking was different enough from our linux test version that it made it difficult to port.

In that case, are there any C++ based alternatives that you could suggest similar to NetworkTables that can easily send data to and from the robot? I would rather avoid using Java if at all possible, because none of the mentors on my team are familiar with that language.

I wouldn’t mind teaching myself some network socket programming if need be. If you could direct me to documentation of any kind relating to communicating between the robot and the driver station, that would be great. Thanks for the response!


We are facing the same problem / opportunity.

We have recently made good progress in building a prototype interface between C++ and the networktables-desktop.jar java library on the drive laptop Windows platform by using JNI (Java Native Interface).

There is also suggestion from charrisTTI via ChiefDelphi a few years ago at that IKVM can be used to convert the .jar into a .dll. Generally, see: . I have tried it, but I haven’t myself had much luck with that beyond the immediate conversion.

It’s a little subtle, though.
Basically, the plan is:
-create a JVM instance with its class path pointing at the networktables-desktop.jar
-find and call the appropriate Java methods
If using Visual Studio 2010 C++, which is what we are doing, one has to take some care that the system PATH environment variable is set correctly for the JRE (Java Runtime), etc.

If there is interest, I may be able to post very rough but working code samples via GitHub.

I look forward to responses.


Martin Haeberli
(one of many)
Mentor(s) to FRC team 3045 - SWAT - San Mateo, CA

PS - where is the original NetworkTables java code kept - in GitHub? The WPI FirstForge code doesn’t seem to be the most current.

Can you please point us at the official current source code repository for NetworkTables, especially for networktables-desktop.jar

mhaeberli, it would be great if you would share the GitHub codes!

I’ll try to git it posted on Github tonight and then share it…
YMMV (your mileage may vary)

(and other interested parties):
Here is a kludgy first pass:

to test it out without a robot, run TableViewer in server mode on, say, the local host. Let’s say that localhost’s IP address is Change the IP address in the code to “”. (and the PATH environment variable needs to be right, and this code assumes that networktables-desktop.jar is at C:\Windriver\WPILib\desktop-lib) The JDK and/or the JRE needs to be installed already. I suspect that I have left some dangling references in, which may be why the destroyJVM call had to be commented out.
This is NOT a complete interface to NetworkTables; additional methods can be added. I’ll try to post the method signatures for the whole NetworkTables as an additional commit later.
Please let me know if you have any questions.

I’m guessing everyone here that has posted here has already considered / tried this already, but why not just use TCP / UDP? My team has tried sending data from computer to computer with success, and there’s a lot of documented instances of teams using either protocol to send information to and from the cRIO (most of what I’ve seen have been in regards to sending stills gathered from vision processing to the DS). What we’ve tried hasn’t been particularly difficult, but we have yet to try to integrate with the cRIO…

Hi ekapalka,

I’m probably just being dense, but it looks like the standard C++ runtime WPILib on the robot end does not directly support TCP / UDP. NetworkTables support is included.

It looks like there is at least some sockets support in the robot-side Java code. But our team has chosen for whatever set of reasons to use C++ both on the drive station side and on the robot.



I don’t think it’s practical, but I based on what I’ve seen in the NetworkTables code in WPIlib, it appears that VxWorks uses the Berkeley (BSD)/POSIX sockets API (so most Linux / Unix socket code should function). If I’m wrong about that, I’m sure that this thread has sufficient information on how to do it (just skip past all the pessimism in the first few posts) :slight_smile:

The operating system supports TCP/IP via the Berkeley socket interface. Support via the WPI and/or NI libraries is unnecessary. Most Linux networking example code on the net will run with few or no changes on the robot (in C or C++).


wireties / Keith,
Thanks for that observation. We’ll keep it in mind.
That said, NetworkTables looks pretty easy to use, now that we have the framework in place.

The pynetworktables project provides bindings to NetworkTables in python. They have been tested on Linux, Windows, and OSX.

The python bindings are based on the C++ WPILib source releases. Some changes have been made to support building on other platforms, like windows. You can find the fixed version of WPILib (which includes NetworkTables) on github, you should be able to build it on Windows without any problems if you create a usable build environment for it. Note that you will need your own implementations of some of the WPILib/vxWorks components to build it – the components that pynetworktables uses is found here.

I’ve had the Windows version of NetworkTables C++ working for over a year now. Perhaps you guys should borrow my changes? (see above)

I’d welcome a pointer to your changes - on first examination I don’t see your C++ NetworkTables code in the three links in your signature block.

See above. :slight_smile:

OK (light bulb goes on!) so - the pynetworktables implementation you wrote has a complete NetworkTables implementation in C++. Again, because I’m dense, it would have been a bit clearer had you said: “see, for example, ;
The branding as “pynetworktables” was tied in my brain to Python…

Correct. The python stuff is just a wrapper around the C++ implementation

More importantly to note, the C++ implementation is the same implementation that the robot is running (e.g., that’s why the repository is called WPILib), with some minimal changes to make it work on Windows/Linux. So ideally, the code should work as well as the code that’s running on the robot.