views:

503

answers:

3

I've got a couple questions about sending images over.

How do I handle different types of files, jpeg, png, etc.

If the file is large, I ave to use sequence numbers... but I don't know how to stop recving if I do not know the number of sequence numbers.

My knowledge of transfering images / files is next to none. I have never programmed anything like that before. Was hoping to get some tips and tricks =)

Thanks alot.

I am also using QT, if that helps my situation at all.

A: 

Transfer them as you would any other binary data. send(), recv(). Or whichever abstraction Qt provides.

Alex
Ahh, how would I change the data into binary? and then convert it back from binary to that file type? - sorry noob at work
NeverAgain
You don't convert it to binary. It already is.
Alex
+1  A: 

If you use a TCP socket, you need no sequence numbers, because TCP already ensures that data arrive in the same order as they where send. Just send the data, and when done close the connection. Optionally you can use some self-defined type of packet header that gives additional information (e.g. if you want to transmit multiple files over one connection).

Space_C0wb0y
Ahhh, nice, yeah I am using TCP. Thanks =)Oh, I was wondering... do you know where I could find an example? I'm looking around, but I still can't find something simple... that and it is almost morning zzzZZzzzzZ
NeverAgain
Can't really help you there, never used QT.
Space_C0wb0y
+2  A: 

For images at least, assuming you are using QImage, you can use a QDataStream to convert your QImage to a QByteArray, which can then be written to the QTcpSocket object using write(). It is possible to serialize pretty much any of Qt's data types into a QByteArray using this method.

For general files, the QIODevice (base for QFile, among others) provides read functions such as readAll(), which will read the whole file into a QByteArray ready for you to send.

You will find a number of networking examples included with the Qt distribution. See Qt Assistant -> Contents -> Tutorials and Examples -> Network for more information.

badgerr