Qt例程之udp socket

weather station

the QUdpSocket class provides a UDP socket.
UDP (User Datagram Protocol) is a lightweight, unreliable, datagram-oriented, connectionless protocol. It can be
//用户数据协议是一个轻量,不可靠,数据报式的 ,无连接的协议
used when reliability isn’t important. QUdpSocket is a subclass of QAbstractSocket that allows you to send and receive UDP datagrams.
//当连接是不重要时可以使用,QUdpSocket是QAbstractSocket的子类,允许发送和接收udp数据报

bool QUdpSocket::bind(const QHostAddress & address, quint16 port)

Binds this socket to the address address and the port port. When bound, the signal readyRead()
//绑定socket到地址和端口,绑定时,当udp数据报到指定地址和端口时,信号readyRead发射,
is emitted whenever a UDP datagram arrives on the specified address and port. This function is useful to write UDP servers.

bool QUdpSocket::hasPendingDatagrams() const
Returns true if at least one datagram is waiting to be read; otherwise returns false.
//当至少有一个数据报在等待读时 会返回真,否则返回错误

weather ballon

qint64 QUdpSocket::writeDatagram(const char * data, qint64 size, const QHostAddress & address, quint16 port)
Sends the datagram at data of size size to the host address address at port port. Returns the number of bytes sent on success;
//在port发送指定大小的数据报到host,返回成功发送的字节数
otherwise returns -1.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章