本文整理汇总了C++中QTcpSocket::isWritable方法的典型用法代码示例。如果您正苦于以下问题:C++ QTcpSocket::isWritable方法的具体用法?C++ QTcpSocket::isWritable怎么用?C++ QTcpSocket::isWritable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTcpSocket
的用法示例。
在下文中一共展示了QTcpSocket::isWritable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendData
bool Server::SendData(QHostAddress ip_to, QString message)
{
bool result = false;
QTcpSocket* tcpSocket = sockets->value(ip_to.toIPv4Address(), 0);
if (tcpSocket && tcpSocket->state()==QAbstractSocket::ConnectedState && tcpSocket->isWritable()) {
emit write_message(tr("Sending data (size=%1) to %2. Content: \"%3\"").arg(message.length()).arg(ip_to.toString()).arg(message));
tcpSocket->write(message.toUtf8());
result = tcpSocket->waitForBytesWritten();
} else {
tcpSocket = new QTcpSocket();
tcpSocket->connectToHost(ip_to, remote_port, QIODevice::ReadWrite);
tcpSocket->waitForConnected(5000);
if (tcpSocket->state()==QAbstractSocket::ConnectedState) {
emit write_message(tr("Sending data (size=%1) from new socket to %2. Content: \"%3\"").arg(message.length()).arg(ip_to.toString()).arg(message));
tcpSocket->write(message.toUtf8());
result = tcpSocket->waitForBytesWritten(5000);
} else {
emit error(tr("Client \"%1\" not found").arg(ip_to.toString()));
}
tcpSocket->abort();
delete tcpSocket;
}
return result;
}
示例2: SendData
bool Server::SendData(QString message)
{
bool result = false;
QTcpSocket* tcpSocket = getRemoteSocket();
if (tcpSocket && tcpSocket->state()==QAbstractSocket::ConnectedState && tcpSocket->isWritable()) {
emit write_message(tr("Sending data (size=%1) to server. Content: \"%2\"").arg(message.length()).arg(message));
tcpSocket->write(message.toLocal8Bit());
result = tcpSocket->waitForBytesWritten();
if (!result) {
emit error(tr("Sending error: %1").arg(tcpSocket->errorString()));
} else {
tcpSocket->flush();
}
}
return result;
}