Solved Receiving Data QTcp Socket
-
Re: TCP connection for file transfer
Hey Everyone,
i'm working on an application that sends files between two Computers in a Lan Environment. I set my Device as a server. When a Client connects the Server should answer with the file.
Here's the Code to the Server:void Server::start() { QHostAddress pHost; pHost.setAddress("192.168.10.11"); QString printAddress; printAddress = pHost.toString(); printf(QString("starting Host under " + printAddress + " \n").toStdString().c_str()); if (this->listen(pHost, 49688)) { printf(QString("Server started and Listening \n").toStdString().c_str()); } else { printf("Server could not be started \n"); } } void Server::incomingConnection(qintptr m_socketDescriptor) { printf("incoming Connection \n"); SocketThread *thread = new SocketThread(m_socketDescriptor, this); connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start(); //this jumps directly to the run function in the socket thread. }
When I connect the two Computers with a LAN Cable a TCP-Connection is established. The IncomingConnection() Method fires and responds with sending a file to the connecting Device.
Now my Question is how to receive the Data on the other End. I already wrote the Code to it but should this Code be running on the Client Device?? Do I have to install QT on the Client Device and run that Code there?
I know this may be a stupid question but I'm very new to network programming.
If I have 10 Client Devices does it mean I have to install Qt and run the Client Code on everyone of them?Every hint is highly appreciated! Thanks !!
-
@JohnSRV said in Receiving Data QTcp Socket:
I already wrote the Code to it but should this Code be running on the Client Device??
I don't understand the question. If client device is connecting to the server then the the client code needs to run on that device of course - where else should it run?
"Do I have to install QT on the Client Device and run that Code there?" - does this code use Qt? If so, then you need to deploy used Qt libraries together with this application to the device. See https://doc.qt.io/qt-5/deployment.html Then there is no need to install Qt on the device.
"If I have 10 Client Devices does it mean I have to install Qt and run the Client Code on everyone of them?" - of course you have to run that code on each of them, how else should it work?
-
@jsulm thanks. I just got a bit confused. I have another Question though. Does connecting the two Devices with a LAN Cable establish a Client Server Connection between the two Devices ??
-
@JohnSRV
That's an equally confusing question :)Nothing establishes a "client/server connection" other than code you run to make something behave as a TCP client or a server.
If you have a LAN cable connecting a PC plus two devices you have three total devices on the network. Each one has an IP address, and each one can access (to whatever extent) the others via appropriate IP addresses.
You will run code on the PC to make it a TCP server and run code on the external devices to make them TCP clients.
Does that help? :)
-
@JonB Yes !! Thanks ! That's exactly what i wanted to know. I know it sounded confusing but I'm very new to Network and Network programing. Thanks !