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.

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