epoll无法接收udp数据包
Can epoll receive udp packet?
我是网络编程的新手,听说过epoll。我读了一些教程,现在我对epoll的作用以及如何实现有了一些基本的了解。
问题是,即使客户端将使用udp连接,我也可以使用epoll吗?我读过的所有教程都使用了tcp连接。
还有一个很好的教程或示例代码可以解释使用epoll实现基于多线程的服务器吗?我从网上得到的那些教程只展示了如何在单线程上创建一个简单的echo服务器。
提前谢谢。
将epoll与UDP一起使用没有问题,epoll只会通知文件描述符中是否有任何数据要读取。读/写。。。与UDP套接字行为相关的操作(来自epoll的手册页):
For stream-oriented files (e.g., pipe, FIFO, stream socket), the condition that the read/write I/O space is exhausted can also be detected by checking the amount of data read from / written to the target file descriptor. For example, if you call read(2) by asking to read a certain amount of data and read(2) returns a lower number of bytes, you can be sure of having exhausted the read I/O space for the file descriptor. The same is true when writing using write(2). (Avoid this latter technique if you cannot guarantee that the monitored file descriptor always refers to a stream-oriented file.)
另一方面,直接使用epoll不是很常见。使用epoll的最佳方式是使用事件循环库,例如libev或libevent。这是一个更好的方法,因为epoll不是在每个系统中都可用,并且使用这种库,您的程序更具可移植性。
在这里您可以找到一个libev与UDP一起使用的示例,在这里您还可以找到其他与libevent一起使用的例子。
相关文章:
- 发送固定大小的 UDP 数据包
- 使用C++将UDP数据包存储在Structure中
- 在高数据包速率下最大限度地减少丢弃的 UDP 数据包 (Windows 10)
- Qt 在可预测的秒数后跳过 UDP 数据包
- 高频接收UDP数据包:丢包?
- 为 posix recv 设置超时会导致 udp 数据包丢失吗?
- 了解 UDP 数据包大小限制的 TCP 数据包大小限制以及它在 boost::asio 编程级别的含义
- 获取进入UDP数据包的目标端口
- 操纵Windows Explorer窗口时,UDP数据包会掉落
- C++ 使用 recvmmsg 丢弃 UDP 数据包
- 如何在QT中接收适当的UDP数据包
- 使用ASIO捕获大量UDP数据包
- 如何正确接收多播UDP数据包
- 服务器未收到UDP数据包,花费数小时试图找出问题所在
- 当接收缓冲区几乎满时,阻止UDP数据包被部分截断
- 如何检查UDP数据包是否在发送器上发送
- 使用 QNX 实时操作系统实时接收 UDP 数据包
- 高效地发送UDP数据包流
- 为什么我在使用 winsock 时没有收到 UDP 数据包?
- SDL_net UDP 数据包数据