예제 #1
0
파일: Message.cpp 프로젝트: ghostec/White2
void writeMessage(QTcpSocket* socket, QByteArray& data1, QByteArray& data2)
{
  socket->write(IntToArray(data1.size() + data2.size()));
  socket->write(data1);
  socket->write(data2);
  socket->waitForBytesWritten();
}
예제 #2
0
void TCPServer::sendData(const QByteArray &data)
{
    if (!server)
        return;

    // Do nothing if there are no active connections
    if (socketMap.size() <= 0)
        return;

    // Build the message
    QByteArray message;
    message.append("TNO");  // Header
    message.append(IntToArray((quint16) data.size()));
    message.append(data);

    // Send the message
    QMap<QTcpSocket *, QTcpSocket *>::iterator ism;
    for (ism = socketMap.begin(); ism != socketMap.end(); ++ism)
    {
        QTcpSocket *socket = ism.value();

        socketMap[socket]->write(message);
        if (!socketMap[socket]->flush())
            emit warning(classname, "TCP server socket flush failed");
    }

    emit info(classname, "send data: " + QString(data));
}
예제 #3
0
    foreach (QTcpSocket *socket, sockets)
    {
#ifdef OPUS
        socket->write(IntToArray(data.size()));
#endif
        socket->write(data);
        socket->flush();
    }
예제 #4
0
bool Client::writeData(QByteArray data)
{
    if(socket->state() == QAbstractSocket::ConnectedState)
    {
        socket->write(IntToArray(data.size())); //write size of data
        socket->write(data); //write the data itself
        return socket->waitForBytesWritten();
    }
    else
        return false;
}
예제 #5
0
bool TcpClient::writeData(QByteArray data)
{
    if(socket->state() == QAbstractSocket::ConnectedState)
    {
        qDebug() << "sending data: " + QString::fromUtf8(data);
        socket->write(IntToArray(data.size())); //write size of data
        socket->write(data); //write the data itself
        return socket->waitForBytesWritten();
    }
    else
        return false;
}