Results 1 to 3 of 3

Thread: Issue with http server implementation on S60 platform

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Posts
    46
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Symbian S60

    Question Issue with http server implementation on S60 platform

    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 –

    Qt Code:
    1. QNetworkAccessManager * manager = new QNetworkAccessManager(this);
    2. QNetworkRequest getReq;
    3. getReq.setUrl( QUrl( fileurl ) );
    4.  
    5. QNetworkReply *reply = manager->get( getReq );
    6. connect( reply, SIGNAL( readyRead()),this,SLOT( moreData()));
    7.  
    8. connect( reply, SIGNAL( error ( QNetworkReply::NetworkError ) ),
    9. this,SLOT( errorInTransaction( QNetworkReply::NetworkError ) ) );
    To copy to clipboard, switch view to plain text mode 


    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 –

    Qt Code:
    1. serverwindow::serverwindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::serverwindow),clientConnection(0)
    4. {
    5. ui->setupUi(this);
    6. ui->textEdit->append("\nServer started");
    7.  
    8. tcpServer = new QTcpServer(this);
    9. ui->textEdit->append("\nServer listening for connections ....");
    10.  
    11. tcpServer->listen(QHostAddress::Any,80);
    12. connect(tcpServer, SIGNAL(newConnection()), this, SLOT(AcceptClientConn()));
    13. }
    14.  
    15. //---------------- AcceptClientConn() ------------------
    16.  
    17.  
    18. void serverwindow::AcceptClientConn()
    19. {
    20. ui->textEdit->append("\nNew client connection received");
    21.  
    22. clientConnection = tcpServer->nextPendingConnection();
    23.  
    24. connect(clientConnection, SIGNAL(disconnected()),
    25. clientConnection, SLOT(deleteLater()));
    26.  
    27. connect( clientConnection, SIGNAL(readyRead()),
    28. this, SLOT(readClient()) );
    29.  
    30. }
    31.  
    32. //-------------------------------------- readClient() -------------------------
    33. void serverwindow::readClient()
    34. {
    35. //read the data obtained from client
    36.  
    37.  
    38. QTcpSocket* clientSocket = (QTcpSocket*)sender();
    39.  
    40. if(clientSocket->canReadLine())
    41. {
    42. QString curData(clientSocket->readLine());
    43. QStringList tokens = curData.split(QRegExp("[ \r\n][ \r\n]*"));
    44. if ( tokens[0] == "GET" )
    45. {
    46.  
    47. //try to send a file's contents
    48.  
    49. //6. song file
    50. QFile htmlfile("c:\\server_files\\song.mp3"); //3MB file
    51. if (!htmlfile.open(QIODevice::ReadOnly))
    52. return;
    53.  
    54. QByteArray block = htmlfile.readAll();
    55. int sz = block.size();
    56.  
    57. QString content_type = "audio/mpeg;";
    58. QTextStream os( clientSocket );
    59. os << "HTTP/1.0 200 Ok\r\n"
    60. "Content-Type: "<< content_type
    61. <<"charset=\"utf-8\"\r\n"
    62. <<"Content-Length: "<<sz
    63. "\r\n\r\n";
    64. os.flush();
    65.  
    66. // Streaming the file
    67.  
    68. clientSocket->write(block);
    69.  
    70. }
    71. }
    72. clientSocket->close();
    73. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to ada10 for this useful post:

    sana (5th February 2011)

Similar Threads

  1. Sample of Http server
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 30th November 2010, 23:43
  2. Replies: 7
    Last Post: 19th August 2010, 12:49
  3. Qt Http implementation
    By ada10 in forum Newbie
    Replies: 6
    Last Post: 11th August 2010, 23:36
  4. mutithread in http-server
    By chuengchuenghq in forum Qt Programming
    Replies: 1
    Last Post: 8th June 2008, 00:24
  5. Build an HTTP server
    By the_bis in forum Qt Programming
    Replies: 4
    Last Post: 30th March 2007, 07:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.