Is there any c++ tcp server on linux? - c++

I want to develop one no-blocking tcp server with c++, is there any open source project like Twisted ?

Boost.Asio is discussed quite frequently in the boost-asio tag on SO. Copying from the tag wiki that I wrote:
Most programs interact with the
outside world in some way, whether it
be via a file, a network, a serial
cable, or the console. Sometimes, as
is the case with networking,
individual I/O operations can take a
long time to complete. This poses
particular challenges to application
development. The Boost.Asio library is
intended for programmers using C++ for
systems programming, where access to
operating system functionality such as
networking is often require

Have a look at ZeroMQ which has several interfaces, including C++.
It does more that just a socket tcp server, but that is part of the appeal. It is licensed under the very liberal LGPL with optional commercial support.

Take a look at the ACE Toolkit. Especially the Reactor and event demultiplexing and event handler dispatching support. The license is very easy and is similar to the BSD License

Related

Developing Distributed application in C++ using RPC (linux)

I'm developing a distributed application in C++ and need a middleware for that . I have done a comparative and my conclusions are :
CORBA . It's dead :-(
MQ options. Like ZeroMQ+MessagePack or ProtocolBuffers + Something for RPC. So new that there are not a RPC mature library for C++.
ZeroC/ICE. A really good one but not a choice for licences issues.
Dbus. Not so distributed as is for local desktop and with a performance issue for big payload (patch kernel for that in development).
RPC. Old one but for now this is my best choice.
So, what do you think for a distributed application in C++ in the XXI century (2014).
What about Apache Thrift?? any experiences C++ and Apache Thift RPC?
Thanks.
You can take a look at CppRemote library. It is easy to use and object oriented. You write IDL using c++ macro and no need external compiler. Disclaimer: I'm the author of this library.
It really depends upon the application, and expected bandwidth betwesen nodes, and needed scalability (aiming a datacenter supercomputer with millions of cores in hundred thousands of hosts is not at all the same as aiming a few desktops on gigabyte ethernet).
Consider also MPI; if you don't need a lot of bandwidth, consider simpler textual protocols like json-rpc
The Internet Communications Engine (Ice) is a modern and up-to-date RPC Mechanism which supports many languages. You can download it here. Much of the Ice APIs are defined in Slice which is the specification language for Ice.
Slice (Specification Language for Ice) is the fundamental abstraction mechanism for separating object interfaces from their implementations. Slice establishes a contract between client and server that describes the types and object interfaces used by an application. This description is independent of the implementation language, so it does not matter whether the client is written in the same language as the server.
Slice definitions are compiled for a particular implementation language by a compiler for example for C++.
Why don't you try Storm, it's distributed RPC: http://storm.incubator.apache.org/

Scalable server framework in C++

I am looking to write a server application in C++ that is meant to handle tens of thousands of clients simultaneously. It should run under Windows and Linux. I have been looking around for frameworks and libraries and have come across Boost Asio, which seems like a highly mature and widely used alternative. I just have trouble wrapping my head around strands/thread pools, mainly because of the millions of templates. My background is mainly in C, so am not really used to the template mess that Boost in general seems to be full of. I tried to find someone to develop a relatively thin wrapper around Boost Asio that would take care of the threading/synchronization aspect using strands, bind and the like, but have been unable to find someone yet who can do it within my budget (2 or 300 US dollars).
Can any of you recommend any other libraries that scale as well as Boost Asio (e.g. with IOCP on Windows and epoll on Linux etc), or a source where I might find skilled Boost developers looking for smaller freelance jobs?
Thanks very much in advance for any help.
Kind regards,
Philip Bennefall
Best 4 choices i know
I really like zeromq.. but libuv seems interesting.. (libev and libevent are very nice too)
zeromq
libevent (as said)
libev
libuv (Its purpose is to abstract
IOCP on windows and libev on Unix systems and it is node.js network layer)
ACE is the framework you are looking for. Even boost Asio is just an implementation of Proactor pattern, which was introduced by Douglas C. Schmidt. He is best known as the author of POSA Vol.2 and the creator of ACE framework.
The Boost.Asio library offers side-by-side support for synchronous
and asynchronous operations ... based on the Proactor design pattern
[POSA2].
Although it is a cross-platform C++ network framework and uses template,
just simple template is used. (or not at all)
My background is mainly in C, too, and I don't like Boost's massive template-programming style. However, ACE wasn't like that.
Try libevent on for size. Its whole raison d'etre is to address the C10K problem. I'd say it's probably more lightweight than boost.
Try Pulsar Server Framework. Main benefit is it is built over libuv network library (used by node.js) that uses asynchronous I/O based on event loops.
It’s perfectly scalable. You can just go adding servers as your user base increases.
It is designed to work with server farm.
Highly configurable and easy to use
Currently it has been built for Windows x64 server.

Portable lightweight C++ sockets wrapper

I really thought this would be easier to find...
I need a portable c++ sockets wrapper. I'm planning to use it for a windows server application and a client that will be running on a embedded device running ulinux (or something similar). I would use Boost but I need it to be lightweight and easy to add to the embedded device project.
Also I would like it to be a "higher level" wrapper... so it starts a background thread to read data and informs be over a callback...
Any ideas?
I'd suggest Boost.Asio. Despite it's name, you are not forced to use asynchronous I/O. You could use synchronous I/O and threads, as your question implies.
Boost.Asio is a cross-platform C++
library for network and low-level I/O
programming that provides developers
with a consistent asynchronous model
using a modern C++ approach.
Just learn to use the socket API directly. You can then easily wrap it yourself. It's not that hard, and you can get started with Beej's excellent guide. As Beej says:
The sockets API, though started by the
Berkeley folk, has been ported to many
many platforms, including Unix, Linux,
and even Windows.
In his guide he details the very small addition you need to do to get the same API in Windows and *nix systems.
Once you've learned, wrap it yourself if you're so inclined. Then you can control exactly how "lightweight" you want it.
If you really don't like Boost asio then you might like the sockets support in dlib. It is simpler in the sense that it uses traditional blocking IO and threads rather than asio's asynchronous proactor pattern. For example, it makes it easy to make a threaded TCP server that reads and writes from the iostreams. See this example for instance. Or you can just make a simple iosockstream if not acting as a server.
I know this is old, but there is a very nice and simple implementation in below location which I'm using for personal use. Had implemented my own wrapper a while back but lost the code and found this one online which is much better than mine:
http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/practical/
Take a look at ENet http://enet.bespin.org/ it is very lightweight and portable and works on top of UDP, with optional support for reliable packets. It is easy to use, the API is low-level and with little performance overhead. You have a high degree of control over the memory management, which could be good if networking is a bottleneck for you and the malloc/new implementation you use performs badly under multithreading.
It would not be that hard to implement your high level thread “optimally”, since there is optional support for blocking receive and the library is a “library” and not a framework therefore you are the decision maker instead of the library.
Perhaps you can have a look at http://www.pt-framework.org/
Old question, but for C++, BSD style synchronous sockets this is about as minimal baggage wrapper as you can find
http://code.google.com/p/ting/source/browse/trunk/src/ting/net/
It does come with exceptions. You could make a bit more lightweight one as a header-only template library, and maybe make exceptions optional, but that would change the API a bit
POCO network classes are quite similar, but do require more dependencies from other parts of the Poco lib
I'm personally creating my own AsIO wrapper for both TCP and Serial sockets, and I started by reviewing the following tutorial:
https://www.gamedev.net/blogs/blog/950-they-dont-teach-this-stuff-in-school/
and
https://objectcomputing.com/resources/publications/mnb/multi-platform-serial-interfacing-using-boost-a-gps-sensor-and-opendds-part-i/
I found the first one very useful and simple to understand.
C++CSP2
Used it loved it. Stable and powerful

What C++ library to use to write a cross-platform service/daemon?

I wonder what library would ease the development of a cross-platform service/daemon ? (C/C++)
I'm targeting: Windows, Linux and OS X.
Requirements: network operations and serial port communication.
Also it would be nice to have a basic sample service application.
When it comes to Qt you might try qt-service.
A daemon in Linux is really just a process that runs disconnected from a terminal. In Windows, a service is something that can be controlled using the service management API, but once again is basically just a disconnected process. The disconnection aside, daemons & servers don't have much in common, from task to task. There is no requirement, for example, that they be multi-threaded, be asynchronous or perform network I/O. Given that, it's kind of hard to see what a cross-platform library would do.
You should take a look POCO. Depending on what you are doing it could have facilities to do a large amount of the work for you with a lot less work than Boost.
An obligatory mention for ACE though I don't personally care for it much.
Boost probably has most of what you need in terms of threading and networking I/O.
You may also find Qt a good alternative. It also has threading and networking libraries and has a much easier to use & understand event-driven programming model using a run loop. Qt's signal/slot system is very easy to use and ideal for a network daemon/service (Boost also includes a signal/slot system but it is harder to use and does not include an event loop; you have to roll your own using some event library). As a cross-platform library, Qt can handle many of the issues in bridging the Unix (OS X and Linux) vs. Windows mental model for processes, filesystems, etc.
For unit testing, I've been very happy with Google's C++ unit testing library called googletest (though both Boost and Qt also have built-in unit testing systems). It runs on all the platforms you specify. I've done a lot of work with googletest on cross-platform Qt projects and found it quite satisfactory.
I've found a big library in the non-boost version of ASIO. You don't need all boost library but only this little headers-only and very well documented library http://think-async.com/
As examples, a daytime server-client system is implemented in very few lines of code.
Take a look at it.
(remember to look at the non boost-ized version)

Networking with C/C++ in a Windows environment

What is the best way to use sockets on the Windows platform?
Basic sockets I guess, TCP/IP.
Maybe for a chat client, or just for learning.
Could someone give me an example of WININET usage?
maybe ftpgetfile()
That is a very broad question, and depends a lot on your needs.
What level do you need? HTTP/FTP? Or "just sockets" for your own protocol? What kind of performance do you need (amount of connections, expected speed)?
If you choose to go raw API, you should generally stay away from WSAAsyncSelect since performance is abysmal above "a few" concurrent connections. Blocking sockets and thread-per-socket isn't too hot either. WSAEventSelect is slightly tricky, but gets the job done nicely (µtorrent handles a lot of concurrent connections this way). Fancypants really-high-load would be I/O Completion Ports. You could also look into boost ASIO for some portability.
If you want to use standard protocols like HTTP/FTP, check libcurl. Or, for lesser needs and smaller overhead, the standard Windows WININET functions (has a lot of restrictions though).
For using WinINet functions, try starting here - might not be a sample, but at least gives you enough stuff to google for ;)
For basic client server application with TCP/UDP winsock should be sufficient.
Do you mean asynchronous I/O model on windows?
There are select, WSAAsyncSelect, WSAEventSelect, Overlapped I/O, I/O Completion Port, also you may want to use Libevent and Boost Asio which are both cross platform.
WinInet examples you could find in msdn or codeproject.con
Ways to use you could find in nice platofrm independed lib - boost::asio
If you are looking to use this as a learning experience I would also look at ACE. A C++ cross platform framework that implements a lot of the patterns discussed in Patterns for Concurrent Network and Networked Objects. The author has also written on ACE as well (see here).