Implementing a simple server / client concept in C++ - c++

I'm searching for a library / framework / codesnippet that helps me build a really simple server / client. Both should be portable (linux/win/mac).
A picture says more then a thousand words so:
The server should be able to seperate diffrent clients.
What I'm looking for is only a hint on how to do the transfere. I've little experience with languages other then c++, and it was mostly plain easy to create a server that stores all the clients connected in an array and interacts with each one of them once you got pointed in the right direction.
What I looked into for C++ was RakNet and Boost.Asio.
I don't want to use RakNet because I might sell the application at some point (you never know) and Boost.Asio seems way to complex for me to understand and way to low-level. All I really need is a simple send/recieve functionallity.
The json will be handled by me (I already looked into jsoncpp). One message will have a maximum length of 2048 bytes.
Any suggestions / hints / help on what to look into / what to use?
I'm really looking for something easy and not so much low-level to use as I don't need the low-level functionallity.
Thanks in advance,
Robin.

Have you done Network programming before? Its pretty straight forward in C. And what you want can be implemented in a few hours. I used this manual below to finish my assignments back when i was a student.
http://shoe.bocks.com/net/
Just read this and you are good to go. Its really not very hard.
Good Luck!

I enjoyed Beej's guide to network programming.

As cross-platform and easy-to-use are both requirements I would recommend Qt. It's pretty easy, reliable and cross-platform.
http://qt.nokia.com/products/developer-tools/
It comes with lots of samples including 13 networking samples (take a look at the threaded server tutorial which I believe it's just what you're after).

Related

Unmanaged C++ BT/LE on RP/Win and pairing programmatically, possible?

I have an unmanaged c++ application that I'd like to port to Windows Raspberry Pi. It was originally developed on an embedded platform but was written to be highly portable using a pseudo-HAL to wall off the 10-15% of platform specific code. So it easily ports to / runs on windows desktop as well with zero changes to the common ~85%. It's currently written to support ANT+ sensors though we would like to add (or may possibly replace ANT with) BT/LE support. That said from looking at a ton of docs and examples online it's not super clear if it's even possible without a rewrite. If it comes to that though we would probably target linux instead. Anyway, three questions -
(1) Is it even possible?
(2) If so what is the best approach (i.e. what API's should I be looking at, and how should I wrap them for unmanaged use)?
(3) Is there a way to programatically pair the RP with our target sensors on the fly, i.e. scan for available sensors and pair by a predefined type and possibly ID (and again if so what API's should I look at)?
I hate to ask such open ended questions but it's just not clear from the examples I've been looking at online since everything is pretty much UWP oriented and I'm not really familiar with any of that at all. Just looking to get a yes/no on feasibility and a point in the right direction if so. Thanks for any input, chris
Figured I'd follow up on this for anyone else that goes down the same path... here's what I found eventually -
1) Is it even possible... Yes it's possible. I was able to get it working though due to the lack of documentation/examples what I came up with may not be the optimum solution. It does seem solid though from the limited testing I've done.
2) If so what is the best approach... Again, not sure this is the best approach but the very short answer is that do make it work you need to use WRL via COM. All the interfaces needed for both scanning and pairing are found in "windows.devices.enumeration.h" and you'll want to use the following namespaces - ABI::Windows::Foundation; Microsoft::WRL; Microsoft::WRL::Wrappers; ABI::Windows::Devices::Enumeration. Since many of the objects/interfaces you'll need are not documented at all (e.g. "IDeviceInformationStatics2") you'll need to use QueryInterface a good bit to find out what's available.
3) Is there a way to programatically pair... Yes, as noted above it's possible. It took me a few weeks to pick through it all and get it working but looking at the various related examples online and piecing it together it seems to work. One thing that I was concerned about was passing BLE pin codes where needed without a UI. That works too though again not really documented (see "AcceptWithPin")....

C++ on the back end of web app

I have been searching the web for this information and I think I need some help with understanding this better.
I would like to learn how to write back-end of a web application in C++ and essentially how to output C++ to web pages and make it talk to a MySQL database. For the record I can write decent code in C++ but I never did it for web.
Wherever I go on the web and find people asking about this the first list of responses is WHY would you when yo have scripting languages. I am aware of the scripting languages, I have used them for years but I am running across cases where this is a requirement and I would like to learn more about it.
My intent it to write an app that uses Angularjs on the front and C++ on the back. I am a fairly well versed PHP developer and I might take this task on by writing PHP initially but I do need to account for a possibility of rewriting in C++ and this makes me think I should probably write it in C++ from the get go.
I understand that the most usual question is WHY I would use C++ instead of a scripting language so I will try and give a limited set of reasons. Please do understand I am not a pro in this aspect of C++ yet and I am evaluating the situation I am in.
So here are some of my reasons...
The project I am about to take on is bound to be very resource intensive and I would really like to gain all the speed I can possibly get from the get go. The more control I have over the app process the better. Essentially I need precision, I know and love C++ and it allows me to retain the control to a great degree..
The group of people I am talking to in the context of the project are aware of the advantages of C++ fro the resources and speed perspective and they hold a portion of the investment bag which gives them a vote in how the project will be approached. Time IS on my side, but i want to waste as little of it as possible.
I am comfortable with C++, have a C++ oriented mind and would love to use it in this context as much as possible.
So I guess my questions are...
Is there a good tutorial that can take me from the basics to
something intermediate?
How do I write a web site backend in C++?
How do I write C++ to work with MySQL on Linux.
Is there a way to do this on Linux servers?
(I believe Facebook it doing it).
I found this http://www.compileonline.com/compile_cpp_online.php on http://www.compileonline.com and it is giving me hope but I need more information to know how to get there.
I am aware that I am not asking an example code based question but I often find good reference posts on Stack that answer these types of questions so I hope someone can help me. I feel a bit lost here.
My preferred approach to building angular apps is to use the back-end pretty much strictly as a REST server.
Here are a few places that list options:
I'm searching a cgi lib in C to build a restful web service
and
How popular is C++ for making websites/web applications?
and
https://softwareengineering.stackexchange.com/questions/147445/how-does-one-interface-c-with-the-web-at-google-for-example
One option that seems to come up multiple times is http://cppcms.com/. Also http://www.webtoolkit.eu
Integrating angular will be pretty much the same as integrating with any other back-end. If you're using the back-end as a REST server you can pretty much statically serve all of the angular code.

Twisted alternative in C++

I'm looking for something like Twisted in Python (event-driven networking engine). I've found Boost:Asio but it is hard for me. So I need something much easier (without low level programming).
I'd recommend to start with Asio from implementing and changing the examples.
Boost.Asio is the-state-of-the-art today and one of the easiest way to start asynchronous/event-driven networking programming with C++.
So give Boost.Asio 2nd chance as it is one of the best tools around.

Support for XNA WP7 and flash with existing C++ code base - pipeline, tools and approaches

all.
We are game development company and we develop casual games for PC/MAC/iOS/Android with our own engine written in C++ (90-100%) and we are happy with it!
Now we want to target XNA/WP7 and flash.
What is the best way for doing this ?
Of course we will have to rewrite some low-level stuff like sprite rendering/timing/audio support, but we want to put as less efforts as possible in porting game code itself.
A. We do not want to rewrite game code two time more
B. Ideally even one time more :)
For flash we are going to use Haxe together with this library.
It would be awesome to have C# target support in Haxe. It has been announced but never released and I think it will not be released in nearest future. But I think it will be released in 1-2 years. So in porting different engine components to Haxe is potentially great investment.
Until then we have to decide how to meet A and B.
Possible variants for dealing with it:
Using mokey. However languaged seems to be so primitive and so different from C++/AS3/C#/etc what we decided not to use it.
First of all develop XNA port with the help of brains and C++ to C# converter. Then use C# to Haxe converter. This approach seems to be the best one at this moment, but I have no idea about how much time convertors will save compared to straightforward code rewrite. However, I think they will help.
It is also possbile to use Adobe Alchemy for flash support. However we will have to develop new architecture to separate render/audio and logic into different languages and we want to avoid this - it seems to be more complex than code porting.
So what do you think about 1-3 and do you know better options to achieve A and B ?
Maybe other meta languages/approaches/technologies ?
Thanks a lot!
This is your absolute best/ideal solution:
http://www.mandreel.com/?page_id=48
http://www.leebrimelow.com/?p=2593
Basically it's a framework/compiler that will compile c/cpp/objc to iOS, Android, Flash, WP7, and much more.

C++ Server-Side-Scripting

For once, I have come across a lot of stuff about the use of C++ being not advisable for SSS and recommending the use of so called interpreted languages like PERL and PHP for the same. But I need the advanced OO features and flexibility of C++ to ensure a scalable and more manageable code.
I have tried many internet articles and searches and none where helpful to the point that I still have no idea if it is possible to write SS-Scripts in C++ and if yes, then how.
I have thought of couple ideas, including writing a web-server in C++ and responding accordingly after parsing the HTTP request. But it would be re-inventing the wheel and I'll end up deviating from my main project and dedicating a lot of work to ensure a functional-cum-secure HTTP server.
I have also considered PHP extensions but again the approach also comes with its own baggage and overhead.
My questions are:
Is it possible to program SSS in C++?
If yes, then what are the approaches at my disposal.
Thanks!
Ignoring, for the moment, the advisability of using C++ for SSS, your first choice would probably be Wt. Contrary to the implications in some of the other answers, no development time is not likely to increase by 10x (or anywhere close to it). No, you're not missing all the nice infrastructure features you'd expect in things like PHP, Perl or Python either.
In fact, my own experience is rather the opposite: while PHP (for example) makes it pretty easy to get a web site up and running fairly quickly, producing a web site that's really stable, secure, and responsive is a whole different story. With Wt, rather the opposite seems to be the case (at least in my, admittedly limited, experience). Getting the initial site up and running will probably take a little longer -- but about as soon as it looks, acts, and feels the way you want, it's likely to need only rather minor tweaks to be ready for public use.
Getting back to the advisability question: developing in C++ may be a bit more complex than in some languages that are more common in the SSS market -- but it's still a piece of cake compared to doing security well. If somebody has even the slightest difficulty writing C++ (e.g., tracking and freeing memory when it's no longer needed), I definitely don't want them getting close to the code for my web site.
I wouldn't recommend it, but you can certainly write CGI scripts in C++ (or in C, or in FORTRAN). But why bother? Languages like PHP do a much better job more easily, and they seem to scale well for some pretty major sites.
CGI is the "standard" way to have C or C++ code handling web requests, but you might also look into writing a module that gets linked into the web server at runtime. Google for "apache module API" (if using Apache) or "IIS module" (if using IIS).
Can you afford 10x as much development time? All the infrastructure-ish bits that you take for granted in php, perl, python are non existent or much harder to use in C++.
I see only two valid reasons to do this:
1. You only have C++ on your platform.
2. The server really has very high performance needs that would benefit from problem specific optimizations.
You can write a CGI application in C++ using an appropriate framework (like this one). But I'd recommend just going with perl or php. It will save you much time. Those tools are just better suited for this kind of job.
EDIT: corrected the link
I couldn't understand your exact requirements (license, etc) but this might be what you are looking for http://cppcms.sourceforge.net.