Portable Socket programming in C/C++ possible?

2019-07-26 01:16发布

问题:

I am thinking of creating a multi-platform portable C++ server-client application. Is it even possible while using only standard libraries? If no, what other libraries are there?

Are there any improvements in this direction in C++11x? Like for threads, now we have std::threads.

To make it more clear.. I want something like boost::thread, which provides multiplatform portable multithreading, for networking.

And why C++ doesn't have libraries(standard) for such basic things like networking?

Update: Comparing to Python, which has everything (almost) built in to it... why not in C++?

回答1:

There is Boost Asio. It has existed for "only" a small number of years...long ago we had ACE, but it feels dated now.



回答2:

There is no standard portable option in C++11.

However the portable boost::asio is one of the best networking API's. It is based on the proactor pattern which is very efficient.

http://www.boost.org/doc/libs/1_49_0/doc/html/boost_asio.html



回答3:

There have been many attempts to provide such a cross-platform library for networking over the years. The Berkeley socket library comes pretty close (and probably comes with your OS), but there are still platform-specific differences. Qt has network socket classes that attempt to be cross-platform within the subset of platforms that Qt normally supports. You can probably find lots of others.

There is no language standard networking library for C or C++ analogous to std::thread.