Asynchronous sockets
#1 Members - Reputation: 110
Posted 20 March 2012 - 02:22 PM
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?
#2 Moderators - Reputation: 3295
Posted 20 March 2012 - 03:14 PM
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.
#4 Moderators - Reputation: 3295
Posted 20 March 2012 - 07:21 PM
"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.
#5 Members - Reputation: 269
Posted 22 March 2012 - 04:42 AM
http://www.win32developer.com/tutorial/winsock/winsock_tutorial_6.shtm
Async Server
http://www.win32developer.com/tutorial/winsock/winsock_tutorial_7.shtm
#6 Members - Reputation: 2369
Posted 22 March 2012 - 07:58 AM
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 Client
http://www.win32deve...tutorial_6.shtm
Async Server
http://www.win32developer.com/tutorial/winsock/winsock_tutorial_7.shtm
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?
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).
#8 Members - Reputation: 110
Posted 23 March 2012 - 05:55 AM
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
Maybe you could suggest me some tutorials/references?
#10 Members - Reputation: 1283
Posted 24 March 2012 - 12:56 AM
MSDN Documentation is your best bet.Maybe you could suggest me some tutorials/references?
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++.
#12 Moderators - Reputation: 3295
Posted 25 March 2012 - 11:37 PM
Nother Question: How much clients would i be able to handle with a Thread-Per-Client implementation?
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.






