QT之Qudpsocket类的学习笔记

本文详细介绍了如何使用QT中的QUdpSocket类进行UDP通信,包括发送和接收UDP数据报的方法,如writeDatagram()和readDatagram()。通过示例展示了如何创建服务器端监听并读取数据,以及客户端发送广播包。强调了readyRead()信号和hasPendingDatagrams()方法在处理待读取数据报中的作用。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值