1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| void Server::incomingConnection(int sockfd){
std::cout<<"Incomming connection"<<std::endl;
//Chargement image
QPixmap image("img.jpg");
QByteArray array;
QBuffer buffer(&array);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "JPG");
QTcpSocket socket;
if(!socket.setSocketDescriptor(sockfd)){
std::cout<<"Error!"<<std::endl;
return;
}
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << (quint16)0;
out << buffer.data();
// out << "PLop";
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
socket.write(block);
socket.disconnectFromHost();
socket.waitForDisconnected();
} |
Partager