用于 C++ 的套接字 API 或库?

Socket API or library for C++?(用于 C++ 的套接字 API 或库?)

本文介绍了用于 C++ 的套接字 API 或库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近对 ​​C++ 有了更多的了解.我用 C 做了一些(非常少的)套接字编程,但对用 C++ 做一些工作很感兴趣.我只能找到关于基于 C 的套接字实现的参考/教程.是否有一个原因?我知道或相信我知道您可以将 C 套接字库用于 C++,但不确定.

I recently have been getting more into C++. I have done some (very minimal) socket programming with C, but have been interested in doing some work with C++. I have only been able to find reference/tutorials on C based socket implementations. Is there a reason for this? I know, or believe I know that you can use the C socket libraries for C++, but am not sure.

是否有比其他人更频繁使用的 C++ 套接字库?这不是一个主观问题,我实际上是想找出 C++ 的 Socket API/库是什么.

Is there a C++ socket library that is used more often then others? This isn't a subjective question, I am actually looking to find out what the Socket API's/libraries are for C++.

我是套接字编程和 C++ 方面的新手,所以请不要回答会让我陷入困境的答案.

I am fairly new at socket programming and C++, so please no answers that will throw me for a loop.

谢谢

推荐答案

在这里,我试图回答你的一些具体的、事实的问题,我有一些贡献.

Here I'm attempting to answer some of your specific, factual questions to which I have something to contribute.

是的,您可以在 C++ 中使用任何 C 套接字库.如果由于链接器报告您要使用的库函数的未定义引用而无法开箱即用,则可以通过编辑 .h 库文件,在所有函数和全局变量声明前添加 extern "C".

Yes, you can use any C socket library in C++. If it doesn't work out-of-the-box because the linker reports an undefined reference for the library functions you want to use, then can fix it by editing the .h file(s) of the library, adding extern "C" in front of all function and global variable declarations.

要查找库,请转到 http://freshmeat.net/ ,然后搜索 C++ socketC 套接字.这是我为 C++ socket 找到的:

To find libraries, go to http://freshmeat.net/ , and search for C++ socket or C socket. Here is what I've found for C++ socket:

  • Socket++.
  • ENUt.
  • LibSylph.
  • CPPSocket 也可能对您有用,尽管最后一次更新是在 2003 年.
  • SocketW 也同样旧:最后一次更新是在 2003 年.
  • Socket++.
  • ENUt.
  • LibSylph.
  • CPPSocket might also work for you, although the last update was in 2003.
  • SocketW is similarly old: last update in 2003.

正如 Raphael 在他的回答中提到的,您可能会发现 Qt 库的套接字部分很有用.参考 QTCpSocket 和 fortune 客户端 示例代码.

As Raphael has mentioned in his answer, you might find the socket part of the Qt library useful. See QTCpSocket for reference, and the fortune client for example code.

Boost.Asio 也出现在我的请注意,但它可能会为您暴露太多的抽象和低级细节.

Also Boost.Asio has popped to my mind, but it might have too much abstraction and low-level details exposed for you.

在freshmeat 上搜索C socket,你可能会找到比任何C++ 库都更适合的C 库.

Do your search for C socket on freshmeat, you may find a C library which suits better than any C++ library.

这篇关于用于 C++ 的套接字 API 或库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:用于 C++ 的套接字 API 或库?

基础教程推荐