I have a simple application which use QTcpServerand QTcpSocketfor accepting and making connections. the app is working fine on simulator server accept connections exchange data. But when i tested the app on device server listen on local host but fail to listen on WLAN ip. some one have any idea how i can make a server which listen on WLAN ip. Following is my .pro .h and .cpp files. Please Help

.pro file


Qt Code:
  1. #-------------------------------------------------
  2. #
  3. # Project created by QtCreator 2010-11-26T15:34:52
  4. #
  5. #-------------------------------------------------
  6.  
  7. QT += core gui network xml
  8.  
  9. TARGET = J2metest2
  10. TEMPLATE = app
  11.  
  12.  
  13. SOURCES += main.cpp
  14. mainwindow.cpp
  15.  
  16. HEADERS += mainwindow.h
  17.  
  18. FORMS += mainwindow.ui
  19.  
  20. CONFIG += mobility
  21. MOBILITY =
  22.  
  23. symbian {
  24. TARGET.UID3 = 0xe9a8f007
  25. TARGET.CAPABILITY += LocalServices NetworkServices
  26. TARGET.EPOCSTACKSIZE = 0x14000
  27. TARGET.EPOCHEAPSIZE = 0x020000 0x800000
  28. }
To copy to clipboard, switch view to plain text mode 

.h file

Qt Code:
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include<QTcpServer>
  6. #include<QTcpSocket>
  7. #include<QNetworkInterface>
  8.  
  9. namespace Ui {
  10. class MainWindow;
  11. }
  12.  
  13. class MainWindow : public QMainWindow
  14. {
  15. Q_OBJECT
  16.  
  17. public:
  18. explicit MainWindow(QWidget *parent = 0);
  19. ~MainWindow();
  20.  
  21.  
  22. private:
  23. Ui::MainWindow *ui;
  24. QTcpServer server;
  25. QTcpSocket *serverSocket;
  26. QTcpSocket *clientSocket;
  27. void connectToServer();
  28. void startServer();
  29. private slots:
  30. void on_pushButton_2_clicked();
  31. void on_pushButton_3_clicked();
  32. void on_pushButton_clicked();
  33. void newConn();
  34. void serverSocketRead();
  35. void clientSocketRead();
  36. };
  37.  
  38. #endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode 

.cpp FIle

Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4. MainWindow::MainWindow(QWidget *parent) :
  5. QMainWindow(parent),
  6. ui(new Ui::MainWindow)
  7. {
  8. ui->setupUi(this);
  9. connect(&server,SIGNAL(newConnection()),this,SLOT(newConn()));
  10. // connect(clientSocket,SIGNAL(readyRead()),this,SLOT(clientSocketRead()));
  11. // connect(serverSocket,SIGNAL(readyRead()),this,SLOT(serverSocketRead()));
  12.  
  13. }
  14.  
  15. MainWindow::~MainWindow()
  16. {
  17. delete ui;
  18. }
  19.  
  20. void MainWindow::startServer(){
  21.  
  22.  
  23. QString ownIpAddress;
  24. QList<QHostAddress> ipAddressesList = QNetworkInterface::allAddresses();
  25. for (int i = 0; i < ipAddressesList.size(); ++i) {
  26. if (ipAddressesList.at(i) != QHostAddress::LocalHost &&
  27. ipAddressesList.at(i).toIPv4Address()) {
  28. ownIpAddress = ipAddressesList.at(i).toString();
  29. break;
  30. }
  31. }
  32. if (ownIpAddress.isEmpty())
  33. ownIpAddress = QHostAddress(QHostAddress::LocalHost).toString();
  34. if(!server.listen((QHostAddress)ownIpAddress,1235)){
  35. qDebug()<<"server can not be started";
  36.  
  37. }
  38. else{
  39. qDebug()<<"Server started at"<<server.serverAddress()<<"Port"<<server.serverPort();
  40. ui->textBrowser->insertPlainText(tr("server started at : %1 and %2 ").arg(server.serverAddress().toString()).arg(server.serverPort()));
  41. }
  42.  
  43.  
  44. }
  45.  
  46. void MainWindow::newConn(){
  47. char *data = new char();
  48. qDebug()<<"New Connection";
  49. ui->textBrowser->insertPlainText("New Connection");
  50. // qDebug()<<"threads "<<threads.count()<<" Textbrowsers "<<textBrowsers.count()<<"Sockets "<<connections.count();
  51. uint i;
  52. i=1024;
  53. // QString name;
  54. serverSocket =server.nextPendingConnection();
  55. connect(serverSocket,SIGNAL(readyRead()),this,SLOT(serverSocketRead()));
  56. QByteArray block;
  57. QDataStream out(&block,QIODevice::WriteOnly);
  58. // QString a=tr("(iq,bhatti");
  59. //// out<<a.toAscii();
  60. // serverSocket->write(a.toUtf8());
  61. // serverSocket->flush();
  62.  
  63.  
  64. }
  65.  
  66. void MainWindow::connectToServer(){
  67. // char *data = new char();
  68. char *data = new char();
  69. uint i;
  70. i=1024;
  71. uint port;
  72. port = 1235;
  73. QTcpSocket *clientSocket = new QTcpSocket(this);
  74. connect(clientSocket,SIGNAL(readyRead()),this,SLOT(clientSocketRead()));
  75. clientSocket->connectToHost((QHostAddress)"192.168.10.119",port,QIODevice::ReadWrite);
  76. clientSocket->waitForConnected();
  77. if(clientSocket->state()== QAbstractSocket::ConnectedState){
  78. qDebug()<<"Connected to Server";
  79. ui->textBrowser->insertPlainText("Connected to Server");
  80. // clientSocket->waitForReadyRead();
  81. // clientSocket->readLine(data,i);
  82. // qDebug()<<data;
  83. // QString datain = data;
  84. }
  85. }
  86. void MainWindow::on_pushButton_clicked()
  87. {
  88. startServer();
  89. }
  90.  
  91. void MainWindow::clientSocketRead(){
  92. char *data = new char();
  93. uint i;
  94. i=1024;
  95. clientSocket->readLine(data,i);
  96. a = tr("/n Other party Said;")+ data;
  97. ui->textBrowser->insertPlainText(a);
  98. }
  99.  
  100. void MainWindow::serverSocketRead(){
  101. char *data = new char();
  102. QByteArray b;// = new QByteArray();
  103. uint i;
  104. i=1024;
  105.  
  106. b = serverSocket->read(i);
  107. if(b.at(0)=='�'){
  108. b.remove(0,2);
  109. //b.append('�');
  110. }
  111.  
  112. // QDataStream in(b2);
  113. // for(int k=0;k<b.length();k++){
  114. // *(data+k) = *(b+k);
  115. // }
  116. //data = b.data();
  117. // a.fromUtf8(data,20);
  118. //b.remove(0,2);
  119. //b.append('�');
  120. //serverSocin<<b;
  121. //a.fromUtf8(serverSocin);
  122.  
  123. a = b;
  124. qDebug()<<a;
  125.  
  126. // a = tr("/n Other party Said;")+ b.to
  127. ui->textBrowser->insertPlainText(a);
  128. }
  129.  
  130. void MainWindow::on_pushButton_3_clicked()
  131. {
  132. // char *data = new char();
  133. uint i;
  134. i=1024;
  135. // data = ui->lineEdit->text().;
  136. // if(clientSocket->state()== QAbstractSocket::ConnectedState){
  137. // clientSocket->write(ui->lineEdit->text().toLocal8Bit());
  138. // }
  139. if(serverSocket->state()== QAbstractSocket::ConnectedState){
  140.  
  141. QDataStream out(&b,QIODevice::WriteOnly);
  142. out<<ui->lineEdit->text().toUtf8();
  143. serverSocket->write(b);
  144. serverSocket->flush();
  145. }
  146.  
  147. }
  148.  
  149. void MainWindow::on_pushButton_2_clicked()
  150. {
  151. connectToServer();
  152. }
To copy to clipboard, switch view to plain text mode