本文整理汇总了C++中QUdpSocket::waitForBytesWritten方法的典型用法代码示例。如果您正苦于以下问题:C++ QUdpSocket::waitForBytesWritten方法的具体用法?C++ QUdpSocket::waitForBytesWritten怎么用?C++ QUdpSocket::waitForBytesWritten使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QUdpSocket
的用法示例。
在下文中一共展示了QUdpSocket::waitForBytesWritten方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendToEditor
bool EditorPipe::sendToEditor(QString command)
{
QUdpSocket socket;
// Attempt to connect to the LocalServer
socket.connectToHost(QHostAddress::LocalHost, 58487);
if(socket.waitForConnected(100))
{
qDebug() << "Connected";
QString str = QString(command);
QByteArray bytes;
bytes = str.toUtf8();
socket.write(bytes);
socket.waitForBytesWritten(10000);
socket.flush();
socket.disconnectFromHost();
qDebug() << "Bytes sent: " <<command;
return true;
}
else
{
qDebug() << "sendToEditor(QString command) fail to connect: " << socket.errorString();
return false;
}
}
示例2: run
/**
* @brief TransmitterTask::run
*/
void TransmitterTask::run()
{
QUdpSocket socket;
socket.bind(port, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
socket.writeDatagram(data, address, port);
socket.waitForBytesWritten();
socket.close();
qDebug() << "Task:" << address << ':' << port << "<-" << data;
}
示例3: main
//.........这里部分代码省略.........
}
}
QHostAddress theAddress(address);
if (QAbstractSocket::IPv6Protocol == theAddress.protocol())
{
QDEBUG() << "Valid IPv6 address.";
ipv6 = true;
}
QByteArray sendData = sendPacket.HEXtoByteArray(dataString);
QByteArray recvData;
recvData.clear();
int bytesWriten = 0;
int bytesRead = 0;
if(tcp) {
QTcpSocket sock;
if(ipv6) {
sock.bind(QHostAddress::AnyIPv6, bind);
} else {
sock.bind(QHostAddress::AnyIPv4, bind);
}
sock.connectToHost(addy, port);
sock.waitForConnected(1000);
if(sock.state() == QAbstractSocket::ConnectedState)
{
OUTIF() << "TCP (" <<sock.localPort() <<")://" << address << ":" << port << " " << dataString;
bytesWriten = sock.write(sendData);
sock.waitForBytesWritten(1000);
//OUTIF() << "Sent:" << Packet::byteArrayToHex(sendData);
if(wait) {
sock.waitForReadyRead(wait);
recvData = sock.readAll();
bytesRead = recvData.size();
QString hexString = Packet::byteArrayToHex(recvData);
if(quiet) {
o << "\n" << hexString;
} else {
o << "\nResponse Time:" << QDateTime::currentDateTime().toString(DATETIMEFORMAT);
o << "\nResponse HEX:" << hexString;
o << "\nResponse ASCII:" << Packet::hexToASCII(hexString);
}
}
sock.disconnectFromHost();
sock.waitForDisconnected(1000);
sock.close();
OUTPUT();
return bytesWriten;
} else {
OUTIF() << "Error: Failed to connect to " << address;
OUTPUT();
return -1;
}
} else {
QUdpSocket sock;