UDP:
1、用到网络的东西,必须修改工程环境变量,添加: QT += core gui network
2、用到类 QudpSocket ;
Detailed Description
The QUdpSocket class provides a UDP socket.
UDP (User Datagram Protocol) is a lightweight, unreliable,datagram-oriented, connectionless protocol. It can be used when reliabilityisn't important. QUdpSocket is a subclass of QAbstractSocket that allows you to send and receiveUDP datagrams.
The most common way to use this class is to bind to anaddress and port using bind(), thencall writeDatagram()andreadDatagram()to transfer data. If you want to use the standard QIODevice functions read(), readLine(), write(), etc., you must first connect thesocket directly to a peer by calling connectToHost().
The socket emits the bytesWritten()signal every time a datagram is written to the network. If you just want tosend datagrams, you don't need to call bind().
The readyRead()signal is emitted whenever datagrams arrive. In that case, hasPendingDatagrams()returns true. Call

本文详细介绍了如何使用QT中的QUdpSocket类进行UDP通信,包括发送和接收UDP数据报的方法,如writeDatagram()和readDatagram()。通过示例展示了如何创建服务器端监听并读取数据,以及客户端发送广播包。强调了readyRead()信号和hasPendingDatagrams()方法在处理待读取数据报中的作用。
最低0.47元/天 解锁文章
1388

被折叠的 条评论
为什么被折叠?



