Sending files
Hi,
I have already spent two hours on google but didnt find anything usefull. I just want to send a file from server to client.
So it would be nice if someone can give me a link to a example app or tutorial or just explain how to do it in here.
Thanks in advance Markus
The todo of sending files from server to client:
1) server and client connects
2) server announces it will send a file, client responds and opens file with filename given
3) server sends file over network in 4kb chunks (doesn''t matter about the size)
4) server announces end of file, client closes file
5) server and client end connection.
Trying using UDP or TCP for this, I''m not a expert.
1) server and client connects
2) server announces it will send a file, client responds and opens file with filename given
3) server sends file over network in 4kb chunks (doesn''t matter about the size)
4) server announces end of file, client closes file
5) server and client end connection.
Trying using UDP or TCP for this, I''m not a expert.
[Journal]
I would recommend TCP, as (I may be wrnog here) UDP does not guarantee packet losses, which means it may loose data.
- Veni Vidi What?
yea i already have a client and server setup
and having like filesend name is not the problem
checking if server say EOF isnt too difficult as well
but how to create chunks and put them thogether ?
and having like filesend name is not the problem
checking if server say EOF isnt too difficult as well
but how to create chunks and put them thogether ?
This is more like a problem you have to fix yourself. This is what a programmer does, program!
If it was something technical, everyone would help you. But to think up a system, is your own responsibilaty.
--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..
If it was something technical, everyone would help you. But to think up a system, is your own responsibilaty.
--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..
You need to design a protocol.
The protocol typically involves packets.
To be able to tell the end of a previous packet from the start of the next packet (if you''re on top of stream transport like TCP), most protocols start with a length field, or a packet type field, which implicitly determines the length.
For example:
To send a file, the server would allocate an internal "transfer Id", send a "file start" packet to the client, which contains the transfer Id and the name, then keep sending data packets to the client that contain the transfer Id, then send the file end packet to close/deallocate the transfer id.
Because each packet has a length, variable-size data (such as file names or file data packets) can live after the fixed-size header; you figure out how much there is by subtracting fixed packet header size from total packet size.
The reason to use transfer Ids is if you want to send more than one file at a time. You also want to structure the server such that it queues these packets in some kind of timer driven loop, rather than just blasting the data down the pipe, if you want to support other operations while the file transfer is going on.
Search this forum for "packetizing streams" for more information.
The protocol typically involves packets.
To be able to tell the end of a previous packet from the start of the next packet (if you''re on top of stream transport like TCP), most protocols start with a length field, or a packet type field, which implicitly determines the length.
For example:
struct Header { unsigned short length; unsigned short type;};struct FileStartHeader : public Header { unsigned short xfer_id; // data is just the file name};struct FileDataHeader : public Header { unsigned short xfer_id; // data that follows is the file data};struct FileEndHeader : public Header { unsigned short xfer_id;};enum PacketType { PacketTypeNull, PacketTypeFileStart, PacketTypeFileData, PacketTypeFileEnd};
To send a file, the server would allocate an internal "transfer Id", send a "file start" packet to the client, which contains the transfer Id and the name, then keep sending data packets to the client that contain the transfer Id, then send the file end packet to close/deallocate the transfer id.
Because each packet has a length, variable-size data (such as file names or file data packets) can live after the fixed-size header; you figure out how much there is by subtracting fixed packet header size from total packet size.
The reason to use transfer Ids is if you want to send more than one file at a time. You also want to structure the server such that it queues these packets in some kind of timer driven loop, rather than just blasting the data down the pipe, if you want to support other operations while the file transfer is going on.
Search this forum for "packetizing streams" for more information.
enum Bool { True, False, FileNotFound };
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement