简体   繁体   中英

Know of any cross platform socket library (windows & Linux) in C?

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++.

Off-hand, I can think of four libraries:

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.

I don't know one library that complies both Windows and Linux but I think winsock is similar enough to Linux socket programming.

In particular it supplies you 'select()' and the other functions mentioned. I guess you will need a very thin #ifdef wrapper to avoid type casting warnings.

See here the winsock page for select

Ptlib provides cross platform C++ code that works well for sockets. www.opalvoip.org

Copes nicely with threads. Some support for mac and BSD. Under active development and maintainance. MPL Core library in Ekiga - the preferred desktop app that does SIP & H.323

For windows - it compiles with MSVC. for linux, it compiles with gcc autoconf make etc.

OK, it is C++, but you can work with that... Have a the source inside ptlib/samples - there are many examples of using ptlib there.

Boost库包含这些功能。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM