PDA

View Full Version : QTcpSocket problem in file transfer



omprakash
6th May 2008, 19:01
dear friends, i have written two applications.
One is client application using QTcpSocket class.
Another is server application using QTcpServer class.
I am now able to send the string from client to server and viceversa as well.
i have used QDatastream object, normally what has been given in fortune client example.

Now i want to send a file from client to server. But i am not getting how should i start the coding for the file transfer from client to server.....

Plz help me yaar..

wysota
7th May 2008, 07:24
What have you already tried?

omprakash
7th May 2008, 07:36
dear friend
i have tried only sending small strings between two applications.
That is a small message is sent from client application to server and vice versa..
in client i have used QTcpSocket and in server i have used QTcpServer class..
Just as given in fortuneClient and FortuneServer example.
But i need help in transfering a file from client server..
so plz hellp me..

wysota
7th May 2008, 17:28
So why don't you do it the same way?

omprakash
8th May 2008, 20:46
i have used code like below for sending the string.

QByteArray block;
QDataStream out( &block, QIODevice::WriteOnly );
out.setVersion(QDataStream::Qt_4_0);
out<<"SomeString";
out.device()->seek(0);
out << (quint16)(block.size() - sizeof(quint16));
tcpsocket->write(block);

Now just hint me what should i insert into code for my file transfer...
bye

wysota
9th May 2008, 07:33
1. Read a chunk of file to a byte array,
2. Write the contents of the byte array to the socket,
3. Repeat until you reach the end of the file.

Come on, the task is really simple - it fits more for the newbie forum and not the programming forum.

Rajeshsan
25th January 2010, 08:18
Hi omprakash...
I'm trying to send any type of File on Qt using serial port or Socket Packets. I want to know how to do it.How to add headers and footers to it.plz assist me.
Thanking you