Hi All,
I am new to QT and Symbian, and to be honest i have spent a week trying to figure out what is wrong here in my TCP IP Client that runs on Nokia E52, with no luck.
Every time i try to connect to Server using domain name i get error : "Host Not Found"
Every time is use IP addess is get "Permission Denied"
I have tested the Server using SIC Ftp for Symbian and Ftp for Android they all can connect to server using same domain name and the port no, therefore i am sure i have something wrong in my client code. Any help would be greatly appreciated.
Code:-
//TCP_Client.pro
//---------
QT += core gui
QT += network
TARGET = TCP_Client
TEMPLATE = app
SOURCES += main.cpp\
tcp_client.cpp
HEADERS += tcp_client.h
FORMS += tcp_client.ui
CONFIG += mobility
MOBILITY = bearer
symbian {
TARGET.UID3 = 0xe184b214
TARGET.CAPABILITY += "NetworkServies ReadUserData WriteUserData"
TARGET.EPOCSTACKSIZE = 0x14000
TARGET.EPOCHEAPSIZE = 0x020000 0x800000
}
//TCP_Client.pro
//---------
QT += core gui
QT += network
TARGET = TCP_Client
TEMPLATE = app
SOURCES += main.cpp\
tcp_client.cpp
HEADERS += tcp_client.h
FORMS += tcp_client.ui
CONFIG += mobility
MOBILITY = bearer
symbian {
TARGET.UID3 = 0xe184b214
TARGET.CAPABILITY += "NetworkServies ReadUserData WriteUserData"
TARGET.EPOCSTACKSIZE = 0x14000
TARGET.EPOCHEAPSIZE = 0x020000 0x800000
}
To copy to clipboard, switch view to plain text mode
//tcp_client.h
//-------
#ifndef TCP_CLIENT_H
#define TCP_CLIENT_H
#include <QMainWindow>
#include <QTcpSocket>
#include <QtNetwork>
namespace Ui {
class TCP_Client;
}
{
Q_OBJECT
public:
explicit TCP_Client
(QWidget *parent
= 0);
~TCP_Client();
private:
Ui::TCP_Client *ui;
quint16 blockSize;
private slots:
void requestNewFortune();
void readFortune();
};
#endif // TCP_CLIENT_H
//tcp_client.h
//-------
#ifndef TCP_CLIENT_H
#define TCP_CLIENT_H
#include <QMainWindow>
#include <QTcpSocket>
#include <QtNetwork>
namespace Ui {
class TCP_Client;
}
class TCP_Client : public QMainWindow
{
Q_OBJECT
public:
explicit TCP_Client(QWidget *parent = 0);
~TCP_Client();
private:
Ui::TCP_Client *ui;
QTcpSocket *tcpSocket;
quint16 blockSize;
private slots:
void requestNewFortune();
void readFortune();
void displayError(QAbstractSocket::SocketError socketError);
};
#endif // TCP_CLIENT_H
To copy to clipboard, switch view to plain text mode
//tcp_client.cpp
//---------
#include "tcp_client.h"
#include "ui_tcp_client.h"
#include<QtGui>
#include<QtNetwork>
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(requestNewFortune()));
}
TCP_Client::~TCP_Client()
{
delete ui;
}
void TCP_Client::requestNewFortune()
{
ui->textEdit->clear();
ui->textEdit->append("Connecting to " + ui->lineEdit_1->text() + " Port No. " + ui->lineEdit_2->text());
tcpSocket->connectToHost(ui->lineEdit_1->text(), ui->lineEdit_2->text().toInt());
if (tcpSocket->waitForConnected(-1))
ui->textEdit->append("Connected!");
}
{
switch (socketError)
{
ui->textEdit->append("The remote host closed the connection.");
break;
ui->textEdit->append("The host was not found.");
break;
ui->textEdit->append("The connection was refused by the peer.");
break;
default:
ui->textEdit->append( tr("TCP_Client, the following error occured: %1").arg(tcpSocket->errorString()));
break;
}
}
void TCP_Client::readFortune()
{
}
//tcp_client.cpp
//---------
#include "tcp_client.h"
#include "ui_tcp_client.h"
#include<QtGui>
#include<QtNetwork>
TCP_Client::TCP_Client(QWidget *parent) : QMainWindow(parent), ui(new Ui::TCP_Client)
{
ui->setupUi(this);
tcpSocket = new QTcpSocket(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(requestNewFortune()));
connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
}
TCP_Client::~TCP_Client()
{
delete ui;
}
void TCP_Client::requestNewFortune()
{
ui->textEdit->clear();
ui->textEdit->append("Connecting to " + ui->lineEdit_1->text() + " Port No. " + ui->lineEdit_2->text());
tcpSocket->connectToHost(ui->lineEdit_1->text(), ui->lineEdit_2->text().toInt());
if (tcpSocket->waitForConnected(-1))
ui->textEdit->append("Connected!");
}
void TCP_Client::displayError(QAbstractSocket::SocketError socketError)
{
switch (socketError)
{
case QAbstractSocket::RemoteHostClosedError:
ui->textEdit->append("The remote host closed the connection.");
break;
case QAbstractSocket::HostNotFoundError:
ui->textEdit->append("The host was not found.");
break;
case QAbstractSocket::ConnectionRefusedError:
ui->textEdit->append("The connection was refused by the peer.");
break;
default:
ui->textEdit->append( tr("TCP_Client, the following error occured: %1").arg(tcpSocket->errorString()));
break;
}
}
void TCP_Client::readFortune()
{
}
To copy to clipboard, switch view to plain text mode
//main.cpp
//--------
#include <QtGui/QApplication>
#include "tcp_client.h"
int main(int argc, char *argv[])
{
TCP_Client w;
#if defined(Q_WS_S60)
w.showMaximized();
#else
w.show();
#endif
return a.exec();
}
//main.cpp
//--------
#include <QtGui/QApplication>
#include "tcp_client.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
TCP_Client w;
#if defined(Q_WS_S60)
w.showMaximized();
#else
w.show();
#endif
return a.exec();
}
To copy to clipboard, switch view to plain text mode
//tcp_client.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TCP_Client</class>
<widget class="QMainWindow" name="TCP_Client">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>230</width>
<height>239</height>
</rect>
</property>
<property name="windowTitle">
<string>TCP_Client</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>10</x>
<y>54</y>
<width>211</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Connect and Send Message</string>
</property>
</widget>
<widget class="QTextEdit" name="textEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>211</width>
<height>151</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_1">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>131</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>xxxxxx.co.uk</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2">
<property name="geometry">
<rect>
<x>150</x>
<y>10</y>
<width>71</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>12345</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_3">
<property name="geometry">
<rect>
<x>10</x>
<y>32</y>
<width>211</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Hello World TCP_Client</string>
</property>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TCP_Client</class>
<widget class="QMainWindow" name="TCP_Client">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>230</width>
<height>239</height>
</rect>
</property>
<property name="windowTitle">
<string>TCP_Client</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>10</x>
<y>54</y>
<width>211</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Connect and Send Message</string>
</property>
</widget>
<widget class="QTextEdit" name="textEdit">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>211</width>
<height>151</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_1">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>131</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>xxxxxx.co.uk</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2">
<property name="geometry">
<rect>
<x>150</x>
<y>10</y>
<width>71</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>12345</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_3">
<property name="geometry">
<rect>
<x>10</x>
<y>32</y>
<width>211</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Hello World TCP_Client</string>
</property>
</widget>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
To copy to clipboard, switch view to plain text mode
Bookmarks