Archived

This topic is now archived and is closed to further replies.

Patate

Sending files

Recommended Posts

Hello, I have a question : how can I send files ? Now I open and read the file and send packets of some bytes and the client recv and write the receveid data.. But that s don t work.. do I have to send my data in binaries or charachter mode ? Please help me if you have advices or a code example ! :/ Thx a lot and sorry for my english

Share this post


Link to post
Share on other sites
just make sure to open the files in binary mode

then read a buffersize of the data(say 1024 or so), send it, then have the reciever write it to the file, until there is no more data to send. you might have to implement some kind of packaging system to tell what chunks are what, and when to have the reciever close the file

Share this post


Link to post
Share on other sites
Thx a lot

Now I send my files in binary mode but how do I write the received data ? open the file and write in ? That''s don t work..

Perhaps it s due to format of the data ? Have you some function''s example ?

Thx for you help

Share this post


Link to post
Share on other sites
thx KalvinB and barazor, I will try to expose my problem with pseudo code :

//
server side :
int hfl = _open(PATH, _O_RDONLY, _O_BINARY);
_read(hfl, BUFFER, Size);

Sending BUFFER as a string...

client side :
Receiving BUFFER as a string...

int hfl = _open(PATH, _O_RDWR | _O_CREAT, _O_BINARY);
_write(hfl, DATA, Size);
close(hfl);
//

it is right ? that''s don''t work...
for example when I send a bitmap I received strange data but for text like *.cpp, *.ini etc.. that''s work.

I don''t understand, please help me !

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sorry, this is slightly off the topic here, but i''m wondering if files are stored on hard drives in network byte order or something? Obviously an FTP server/client don''t know the contents of a file and can''t change the byte orders as it''s sending a file when exchanging between the two cpu types, is there anything special that needs to be done when transferring files between a big and little endian computer?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Yes, but a stream of bytes is also just a stream of bytes (ie. sending data across a network). If i have an integer, or some other date, and write it to a file, surely the order is not random.

Share this post


Link to post
Share on other sites
Well, whatever byte-order you used to write to the file, will
be sent across the network. This has nothing to do with
sending files. We treat the "file" as a whole. We certainly
don''t want the file to be FTP''d and come out different from
the original. I think you are just very confused.



Kami no Itte ga ore ni zettai naru!

Share this post


Link to post
Share on other sites