Hi,
I'm trying to develop client and server.
client connects to server and sends raw data.
This is how client sends data: (I need to send it like raw data)
client->abort();
client->connectToHost("my Ip",2342); // for ip I use dyndns
out << out.writeRawData("353184039611442", 14);
client->write(block);
client->disconnectFromHost();
client->abort();
client->connectToHost("my Ip",2342); // for ip I use dyndns
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out << out.writeRawData("353184039611442", 14);
client->write(block);
client->disconnectFromHost();
To copy to clipboard, switch view to plain text mode
Client code is good, I just can't read it on server.
Server listens for connection and tries to read data.
//constructor//
ServerStart();
connect(&Server, SIGNAL(newConnection()),
this, SLOT(ServerAcceptConnection()));
void MainWindow::ServerStart()
{
}
void MainWindow::ServerAcceptConnection()
{
clientConnection = Server.nextPendingConnection();
connect(clientConnection, SIGNAL(readyRead()),
this, SLOT(readData()));
}
void MainWindow::readData()
{
while (clientConnection->bytesAvailable())
{
qDebug()<<"data reading started";
in >> b;
byteArray1.append(b);
}
srt.append(b);
qDebug()<< byteArray1.toHex();
qDebug()<< srt;
}
//constructor//
clientConnection=new QTcpSocket (this);
ServerStart();
connect(&Server, SIGNAL(newConnection()),
this, SLOT(ServerAcceptConnection()));
void MainWindow::ServerStart()
{
Server.listen(QHostAddress::Any, 2342);
}
void MainWindow::ServerAcceptConnection()
{
clientConnection = Server.nextPendingConnection();
connect(clientConnection, SIGNAL(readyRead()),
this, SLOT(readData()));
}
void MainWindow::readData()
{
QString srt, a;
QByteArray byteArray,b,byteArray1;
QBuffer buffer(&byteArray);
buffer.open(QIODevice::WriteOnly);
QDataStream in(clientConnection);
while (clientConnection->bytesAvailable())
{
qDebug()<<"data reading started";
in >> b;
byteArray1.append(b);
}
srt.append(b);
qDebug()<< byteArray1.toHex();
qDebug()<< srt;
}
To copy to clipboard, switch view to plain text mode
I get this result
"192.168.1.1"
data reading started
""
""
Can't understand, what I'm doing wrong.
Bookmarks