I'm about to develop some sockets related stuff in C++ and would like the software to be as portable between Windows and Linux as possible right from the start (making it portable later is tricky.)
I've looked at different libraries, there is one for C++ from alhem.net and of course there is boost::asio. boost::asio looks very promising but would be a very big dependency for applications this small.
Is it even worth writing the stuff myself or should I just use a library? If I do it myself what would be the main pitfalls?
Winsock2 is completely backwards compatible with the original winsock, so the only reason you would ever want to use the original winsock is when you are targeting a platform that doesn't support winsock2 (Everything that is newer than Windows 3.11 supports winsock2 I believe).
3.10 - Is Winsock thread-safe? On modern Windows stacks, yes, it is, within limits. It is safe, for instance, to have one thread calling send() and another thread calling recv() on a single socket.
Winsock allows Windows programs and applications to connect to the internet through TCP/IP. Here are some of its most important features: Winsock exists as a data link layer, and is also known as winsock. dll in our computers. It's a dynamic library extension link.
Run-time requirementsWindows Sockets 2 can be used on all Windows platforms.
I've developed a few portable wrappers around sockets. Make sure you don't go down the crappy lane of no return that is constituted of WinSock2 events. Other than that, as I see it, the biggest differences are:
::WSAStartup()
, to shut it down in Windows, run ::WSACleanup()
; in Linux do nothing,close()
in Linux is closesocket()
in Windows,SO_RCVBUF
and SO_SNDBUF
,::ioctlsocket()
in Windows, ::fcntl()
in Linux,<sys/socket.h>
and friends in Linux, <WinSock.h>
in Windows,::select()
to wait for data to arrive,fd_set
s are totally different on Windows/Linux; this is only relevant if you need to optimize initialization of fd_set
s, such as when adding/removing arbitrary sockets,::recvfrom()
, you might consider using ::sendto()
to release the stalling thread under Linux.Everything else I ever needed just worked out of the låda.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With