I am looking to do socket communications (listen, accept, connect, recv, send, disconnect) in both linux and windows. My project is in C, so unless someone can think of a way for me to integrate C++ libraries into a C project the library will have to be in C as well.
Ultimately, I would like the library to have ipv6 support and non-blocking mode, however, these things are not essential.
Does anyone know of any libraries/cross-platform example code? Even just large code snippets would help. So far the few socket libraries I have found have been in C++.
The regular sockets (those in AF_INET address family) which you need to build a socket server are equally supported on all platforms.
Run-time requirementsWindows Sockets 2 can be used on all Windows platforms.
This means that on Linux and macOS, you can generally use all of the general purpose file functions with socket handles (e.g. read() , write() ). On Windows, socket handles can only be used with special socket functions.
A socket library is a library that implements sockets so that you can use them in your program for Internet communication.
Off-hand, I can think of four libraries:
GLib Channels from the GLib framework can abstract socket usage, but you'll need platform-specific code for socket creation.
libuv is a platform abstraction layer for node.js and handles, among other things, sockets and async IO.
The Apache Portable Runtime also contains network routines.
The Netscape Portable Runtime does socket manipulation as well.
The plibsys library provides all the requested features: cross-platform and portable, lightweight, provides socket IPv4 and IPv6 support as well as many other useful things like multithreading. Works with sockets in non-blocking mode (though you can switch to a blocking one, too). Has quite a good documentation with the test code examples.
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