• Advertisement
Sign in to follow this  

Asynchronous sockets

This topic is 2159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone! As you may see I'm new to this community, and i've got a question.

Can anybody tell me where to learn Asynchronous sockets in c++? Would be nice if you could show me some examples as well. And I don't want to use Boost. Maybe anyone knows any other good networking library?

Share this post


Link to post
Share on other sites
Advertisement
I know of no other cross-platform asynchronous socket library than boost::asio.
If you want to learn asynchronous sockets programming otherwise, you'll have to specify what OS you want it for (BSD, MacOS X, Linux, Windows NT, Solaris, AIX, ...) because they are all different APIs.

Share this post


Link to post
Share on other sites
So, on Windows, "asynchronous sockets" actually means an old way of talking to sockets used in the Windows 3.11 and Windows 95 days, where sockets send messages to the windows message loop. You *really* don't want to be using that, as it's full of bugs and pitfalls, and performs poorly.

"Asynchronous sockets" in the sense of "asynchronous I/O" on Windows is called "Overlapped I/O with I/O Completion Ports." There are some decent explanations and sample code for how this works on msdn.microsoft.com, but you have to dig a bit to find them. Generally, on modern Windows, a socket is a file handle, so you can use ReadFile with an OVERLAPPED struct to post an asynchronous request, for example.

I would recommend using boost::asio, though.

Share this post


Link to post
Share on other sites

Async Client

http://www.win32deve...tutorial_6.shtm

Async Server

http://www.win32developer.com/tutorial/winsock/winsock_tutorial_7.shtm

I really wouldn't use that. It's painfully bound to windows message pipeline and its once-intended use offers no real advantages. Even if it might look sensible for typical Win32 GUI application, such approach makes no sense on headless server.

Async today, for all intents and purposes means IOCP, epoll or kqueue, perhaps through one of common libraries: asio, libevent or ACE. Or just use them directly. Most of these libraries also extend beyond just network to files and possibly DMA transfers (aka fast copying).

.Net's async networking via C# perhaps might be a decent place to start, at least the general concepts transfer and might be easier to experiment with.

And I don't want to use Boost. Maybe anyone knows any other good networking library?[/quote]

What precisely would "good" mean? asio would be the de-facto C++ networking library. libevent is its counterpart for C. And ACE... it has kitchen sinks.

All of these provide some required functionality that isn't directly available or quite straightforward when using underlying APIs (timeouts come to mind).

Share this post


Link to post
Share on other sites

Async Client
...
Async Server
...


Those are *exactly* the Windows 3.1 APIs that I recommended against using. They are old, perform terribly, have bugs, and are hard to use.

Share this post


Link to post
Share on other sites

Those are *exactly* the Windows 3.1 APIs that I recommended against using. They are old, perform terribly, have bugs, and are hard to use.


I already started reading on IOCP anyway smile.png i saw this tutorial earlier, It's for a Win32 app, I'm making my server in a form of a CMD tongue.png
Maybe you could suggest me some tutorials/references?

Share this post


Link to post
Share on other sites

Maybe you could suggest me some tutorials/references?

MSDN Documentation is your best bet.
For TCP read the MSDN documentation for: WSASocket, bind, listen, AcceptEx, WSAConnect, WSARecv, WSASend, CreateIoCompletionPort, GetQueuedCompletionStatus
For UDP read the MSDN documentation for: WSASocket, WSARecvFrom, WSASendTo, CreateIoCompletionPort, GetQueuedCompletionStatus

I think those are the major ones. They will lead you to everything else. However, I would recommend using boost::asio. It basically just wraps everything and gives a clean interface to do the same thing in C++.

Share this post


Link to post
Share on other sites
Nother Question: How much clients would i be able to handle with a Thread-Per-Client implementation?

Share this post


Link to post
Share on other sites
Nother Question: How much clients would i be able to handle with a Thread-Per-Client implementation? [/quote]

No idea. How about you try it and report back? Note that it depends on the hardware and OS you're using, as well as other parameters.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement