View Full Version : Issue with http server implementation on S60 platform

21st September 2010, 10:00
I am facing some issue related to http file download using QT APIs. My simple HTTP Client application sends a HTTP get request using QNetworkRequest. The code is as shown below –

QNetworkAccessManager * manager = new QNetworkAccessManager(this);
QNetworkRequest getReq;
getReq.setUrl( QUrl( fileurl ) );

QNetworkReply *reply = manager->get( getReq );
connect( reply, SIGNAL( readyRead()),this,SLOT( moreData()));

connect( reply, SIGNAL( error ( QNetworkReply::NetworkError ) ),
this,SLOT( errorInTransaction( QNetworkReply::NetworkError ) ) );

I have tested the client application using simple QT Http Server implementation ( which uses QTcpServer API ).
The client is able to download small sized files ( < 1MB ), but when I try to download large files ( > 1MB ) , there is an error on the server side & client application does not get the file contents.
This is the scenario when I run both applications on the phone. Has someone faced this issue and come up with probable solutions ?

The server code is as shown below –

serverwindow::serverwindow(QWidget *parent) :
ui(new Ui::serverwindow),clientConnection(0)
ui->textEdit->append("\nServer started");

tcpServer = new QTcpServer(this);
ui->textEdit->append("\nServer listening for connections ....");

connect(tcpServer, SIGNAL(newConnection()), this, SLOT(AcceptClientConn()));

//---------------- AcceptClientConn() ------------------

void serverwindow::AcceptClientConn()
ui->textEdit->append("\nNew client connection received");

clientConnection = tcpServer->nextPendingConnection();

connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));

connect( clientConnection, SIGNAL(readyRead()),
this, SLOT(readClient()) );


//-------------------------------------- readClient() -------------------------
void serverwindow::readClient()
//read the data obtained from client

QTcpSocket* clientSocket = (QTcpSocket*)sender();

QString curData(clientSocket->readLine());
QStringList tokens = curData.split(QRegExp("[ \r\n][ \r\n]*"));
if ( tokens[0] == "GET" )

//try to send a file's contents

//6. song file
QFile htmlfile("c:\\server_files\\song.mp3"); //3MB file
if (!htmlfile.open(QIODevice::ReadOnly))

QByteArray block = htmlfile.readAll();
int sz = block.size();

QString content_type = "audio/mpeg;";
QTextStream os( clientSocket );
os << "HTTP/1.0 200 Ok\r\n"
"Content-Type: "<< content_type
<<"Content-Length: "<<sz

// Streaming the file



21st September 2010, 18:02
What kind of error?

5th February 2011, 17:44
i think u need set the buffer size and then download it...
can u pl send the complete code