2 QTcpSockets (1 reads another writes) in 2 applications doesn’t work
Hi, i wanna send data from program no.1 with socket A to program no.2 with socket B with 2 QTcpSockets:
In first program i have:
- //in class QTcpSocket *dCtrl
- ui(new Ui::DataAdderItem)
- {
- //(...)
- connect(ui->addNew, SIGNAL(clicked()), this, SLOT(addNewData()));
- //(...)
- }
- void ProxyAdderItem::addNewData(){
- dCtrl->write(str.toAscii());
- //dCtrl->write("aa");
- qDebug() << str.toAscii() << "aa";// write(ui->address->text().toAscii());
- }
and it works. It prints me a text on a terminal’s window.
In second program i have:
- //in class - QTcpSocket* dCtrl;
- {
- //(...)
- dCtrl = new QTcpSocket;
- connect(dCtrl,SIGNAL(readyRead()),
- this, SLOT(addProxy()));
- //(...)
- //connect(dCtrl, SIGNAL(error(QAbstractSocket::SocketError)),
- // this, SLOT(error(QAbstractSocket::SocketError))); // not neccesary
- }
- void ManagerControl::addData(){
- //qDebug("sss");
- //QDataStream in(dCtrl);
- //QString newData = dCtrl->readLine();
- qDebug() << "A";
- qDebug() << newProxy;
- int port = 1238;
- }
And it doesn’t write anything on output (looks like socket is not ready).
What am i doing wrong?
9 replies
Welcome to the forum
Either this part has been excluded or the socket in the NetworkManager does not connectToHost. [doc.qt.nokia.com]
If you are trying to learn how to handle TcpServer/Client with Qt I would recommend starting with the Fortune Server [doc.qt.nokia.com] / Client [doc.qt.nokia.com] example code
That is not the way it is supposed to work.
A server waits for a client to connect.
A client connects to the server.
At the end you will have two sockets communicating.
You should start with the fortune server / client example. It is very simple and it will show you also the way of establishing the communication. (see my previous post)
You will see also that the term server refers to something less sophisticated as you might initially expect.
You must log in to post a reply. Not a member yet? Register here!


