How to implement packet shaping or QOS using c++ library? - c++

I have a question related to networking using c++ in linux.
Description
I am trying to build a client management system that can control bandwidth to each clients. I have tried to search for answers in many places. I end up in LARTC. I think LARTC provides a scripting mechanism to do it. But I want to know pure programming methodology or header file in c programming language (that can communicate to network stack- if any) in linux(Ubuntu 13.04 beta).
Example: I found a header file namely Qos.h in C++. Net (for Windows)

Couple of related questions:
I dont think that out-of-the box solution exists (in a sense of C/C++ API).
How can I programmatically manage iptables rules on the fly?
How to programmatically access iptables?

Related

Web Services using C++

I am building a server-client application that involves heavy signal processing (e.g. FFT). I have a working application written in C++/Qt, where everything (signal processing and other calculations) is done in client and server just sends raw data. Now I feel it would be easier to implement these features on the server. So, that maintenance becomes easier.
As I am doing signal processing, I think I should stick to C++ for performance. But I am open to new ideas.
Constraints:
I need type checking so javascript is out of discussion.
Scaling includes adding more server and each server will have at the max
10-12 users. So, Hardware cost is important. I cannot use x number of
i7 processors.
No option of using cloud services.
So, right now my question is as follows:
How can I create web services using C++ for Linux server? (Although cross platform is not important, I would appreciate if I can achieve it.)
EDIT [02:09:2015]
Right now, I think the choice is between poco and C++ Rest SDK. I feel I should go for C++ Rest SDK. Mainly because it has only those features that I need. And Also it is supported by microsoft and uses boost internally. So, I feel in future, this might be well integreated with standard.
You could use cross-platform Poco library to implement HTTP server, it is really straightforward with this framework, and they have a lot of examples. You can also use JSON serialization (like rapidjson library) to implement REST service on top of HTTP - this way your Web service will be accesable by most of the modern Web frameworks.
You might want to take a look at the C++ Rest SDK, an open source, cross platform API from Microsoft.
Like #nogard suggested, I also recommend POCO for now. It's the most serious and feature-full solution. Given you mentioned Qt, I suggest you to take a look at Tufão.
EDIT:
I forgot to mention one comparison of mine on the C++ HTTP server frameworks.
If you directly handle HTTP requests, you might loose the functionality what Web Servers does well what it was build to do. I had a similar issue, what I did was wrap up my Qt c++ code inside a PHP extension. In your case you can do the same. Wrap your logic inside what ever technology you are about to use, doesn't matter it's PHP, net , Java or anything else.

C++ Parse library for Qt applications

I'm aware there is no official C++ library for Parse (https://parse.com). I've got a desktop variant of an app written using Qt C++ for OSX/Windows that needs to talk to Parse. I'm embarking on writing my own client for the Parse REST API based on the PHP library (https://github.com/apotropaic/parse.com-php-library) and the Qt network classes. Would you recommend a different approach?
The data I am saving is pretty basic, some objects and some geo data, but it would be nice to have a general solution to share with others. I will happily release whatever I come up with via GitHub, and all the better if this can lead to a group of us sharing the load.
Cheers!

How to store preferences (and user settings) in a cross-platform application?

I'm working on a GUI desktop application that should run natively on Windows, Mac OS X and Linux. What is the preferred way to store preferences in a cross-platform application? I'm using C++, but the question (and its answers) should be valid for any natively compiled language. (Solutions for dynamic languages and Java can be seen here.)
My research so far tells me, that there are at least two strategies:
(A) Use the OS-specific API preferences functions.
(B) Store the preferences in a file within an appropriate (OS-specific) folder.
Let's consider method (A): I assume NSUserDefaults is the correct method for Mac OS X. On Windows systems, I'd write to the registry via RegOpenKeyEx. But there arise some questions: Is there any comparable and portable Linux API for that? Is writing to the Windows registry really a future-proof solution?
To keep things simple, I'm inclined to follow method (B). Thus I just have OS-specific code to get the appropriate directory where I can store my data in a format of my choice. On Windows, I've learned SHGetFolderPath (or SHGetKnownFolderPath for recent Windows systems) and CSIDL_LOCAL_APPDATA is the way to go. On Macs, the NSSearchPathForDirectoriesInDomains API call should do the same; it's an Objective-C API though making things more complicated. Finally, for the Linux version using getenv("HOME") (and getpwuid() as a fallback solution) seems to be recommend.
To summarize my questions:
1. Are there any patterns considered as best-practice for this task?
2. Is there any C++ class abstracting all the dirty things like finding the correct folder away out there? (I came across QSetting, but I'm using FLTK and I don't want to change my GUI toolkit.)
Edit:
By "preferences" I mean data that may be changed by the application and the user, e.g. a list of recent files, the preferred window size and so on.
Since z80crew says he's using Fltk in his project, I think the best way to store small amounts of user data is through the Fltk Fl_Preferences class. (http://www.fltk.org/doc-1.3/classFl__Preferences.html).
That way, you don't have to care about where the user data is actually stored in the filesystem. You just create a Fl_Preferences object identified by the name of the application and its vendor (e.g., "CoolApp" and "AuthorOfCoolApp") and Fltk stores the data somewhere.
Under Linux, the preferences are stored in ~/.fltk/{vendor}/{application}.prefs where {vendor} and {application} are the same strings you've passed the constructor of Fl_Preferences. But you aren't supposed to worry about that.
I'm also developing a set of cross-platform plugins and did exactly what you describe in method (B):
Find the proper folder using platform specific code.
Write the preferences to that folder with cross-platform code.
I would also note that:
Using the Windows registry is very limited and problematic. I try to avoid that as much as possible.
Lately apple has a new song: that you should not access the ~/Library/Preferences folder directly but rather use their API for saving preferences value. In effect this turns the preferences into registry like mechanism. I very much resent this approach.
I do not know of any library that implements finding the currect folder in cross-platform manner. Such function is not very hard to write using SHGetKnownFolderPath and NSSearchPathForDirectoriesInDomains, as you described.

Program interacting with web

How or what do I need to know programming wise in order to interact with the web using c++. For instance i want to wrote a program that automatically sends invites to players on yahoo chess. How would i go about doing this?
You'll need to understand the basics of TCP/IP and HTTP, possibly UDP, and the protocols involved with Yahoo's chess systems or posses a tool to work around them (A brief search leads me to believe there are few if any). You'll probably need a network API, I'd suggest looking at:
QtNetwork Module
Boost.Asio
Where Qt is easy to use, Asio is more powerful, and more 'C++' in nature. Qt has some nice webkit components, and I've used it to build a small web server, which was a lot of fun. You can accomplish quite a lot with it.
This page says they've added a captcha system to prevent certain people from interacting with their systems. I'm not familiar with Yahoo games and what the result of this has on what you'd want to do, however it suggests to me they'd rather you didn't write code to interact with their systems.
For this you need to use network APIs and use server side script like PHP/ASP to communicate with the web and C using message queue.

Choosing Cross-Platform GUI Toolkit for Desktop App With WebServices

For a current project, we're designing a client desktop application that parses text files and interfaces with a web based database.
So far we've split the project into parts:
(Third-Party Program) -> (Our Desktop Client) -> (Our Parsing Library #1 and #2) -> (Our Web Server) -> (Our Verification Library) -> (Our Database)
We've hit confusion when it comes to choosing the correct way (and the best language) to make these pieces work together.
The third-party program's output is a simple text file, and we're just parsing it into a SQL-esque format for insertion into our database after verifying the numbers are in a certain range.
The first question we have is regarding the client language itself. We're planning on writing the parser libraries in C++ as they're just mostly text management. Our desktop client needs to be cross-platform for Windows and Mac. Currently we're leaning towards writing this in Java using Swing and the JNI. However, we realize there's a lot of hate for Java and that we'd have to worry about bundling in the JRE.
Is Java a good choice in this situation? Our other options seem to be writing this also in C++ using something like Qt for the GUI, or going platform specific and writing the windows version in .NET and then a Mac specific version. Our Windows community is the vast majority of users.
Our second issue is connecting this client with our web server. Originally we were just going to use an http POST to upload the file. We could also FTP the file which seems like overkill. We started to explore web services but were not sure if a web service could handle large amounts of text data.
Is there an easier way to do this? Everything is text, so it's no problem to send them in chunks or one giant string. If we go the web services route, will that effect our language choice for the desktop client?
There are definitely hundreds of ways to handle something like this, but most of these concepts are new for us. Any suggestions would be greatly appreciated.
Qt is an excellent choice and as it's native C++ it will be easy to integrate with your parsers too. Why write two versions when a single Qt version will run fine on both platforms with native look and feel? Depending on the license you choose you can even statically link Qt if you're concerned about deployment complexity.
A web service would generally have no problem handling large amounts of text and pretty much any language will interact with it easily assuming basic network I/O functionality. Depending on the language you will probably be able to find libraries that do most of the work for you, assuming it's not already supported natively.
As you say, there are many different ways to do what you want to achieve. There is no right or wrong way but obviously some designs will suit your needs better than others.