Grabbing Data in QTcpServer from incoming connection
-
Hello....
I created 2 projects separately. The first program is the client project and the second is the server project.
On client project I have a class with the name ClientTCP that is derived from QTcpSocket, then on server project I have a class with the name SocketServer which is derived from QTcpServerI tried it with the connection. It works. but when I want to grab the data it didnt work.
On class ClientTCP. I want to send a data using TextStream. The code looks like this:
@
void ClientTCP::sendText(QString text)
{
QTextStream out(this);
out << text;
this->waitForBytesWritten();
}
@I want to grab this data that was sent by ClientTCP in my client project on the class SocketServer in my server project. But I have no luck getting the data since it's on another program and I cant include the class since it should stay on the client project.
Can somebody help me?
-
Hi,
Without the code from your server it's pretty much Crystal Ball Debugging. How do you handle the connection on the other side ?
On a side note, you don't need to subclass QTcpSocket in most of the cases, just use a QTcpSocket as member of your Client class
-
Thx for answering. I got it working now, Thanks.
I got another problem. The problem is that if I close the client program. I dont get any notification at all, eventhough I already put a notification when a SIGNAL(disconnected()) is emitted.
Here is the code:
@
Server::Server(QObject *parent) :
QObject(parent)
{
server = new SocketServer(this);
connect(server,SIGNAL(newClientConnection()),SLOT(newClientConnection()));
}void Server::newClientConnection()
{
qDebug() << "New Connection";client = server->nextPendingConnection(); connect(client, SIGNAL(disconnected()), this, SLOT(connectionClosed()));
}
void ServerConnector::connectionClosed()
{
qDebug() << "Client closed connection";
}@
-
Are you properly disconnecting from the client side ?
-
Hello...
Sry for late reply. What I do is I just close the client app. I have another server that was builded using qt3. The server runs perfectly with qt3 since it's there was a signal connectionclosed, but this is not the case in qtcpsocket. I saw some example and implement it the project but it seems didnt work for me.
Another problem I face is:
I need to connect this server A which I make using qtcpserver to another server B which don't use qt at all, The server B is coded using C/C++. The problem is I dont know the structure of the server B. Since I only have a server itself and no code for this at all. My question is: is there a way to connect it? if it does, how?Thanks
-
Sounds like a strange behavior
Depending on what you want from that server your can use QNetworkAccessManager.