What to do
1) At the very beginning of this project, you need to get familiar with (if you have no exposure to operating system before) the linux functions relevant to the following topics:
- Create process
- Partition a large file (e.g .mp3) into packets of fixed size, e.g. 128 bytes each
- Use pipe to send packets from one process to another
- At phase 1, we used named pipe instead of normal pipe. The reason is that normal pipe does not have the feature that the writing end will be blocked if no process reads from the pipe, or the reading end will be blocked if no process writes to the pipe, i.e. a basic flow control is achieved when named pipe is used. Note that in order to implement Selective Repeat, we will eventually replace named pipe with normal pipe, which we will accomplish in phase 4.
2) Decide the structure of a packet
struct packet {
unsigned char Content[128]; // payload
unsigned int EOM; //End Of Message
unsigned int lenOfLastPacket; //because the payload is of fixed size, the sender need to tell the receiver the number of bytes it needs to read from the last packet message_type Type; // {COM, FILEDATA}
}
The size of each packet is 140 bytes. We call all the data stored in the payload of packets "messages". Messages can be commands, which is identified as COM, or binary data, which is identified as FILEDATA. The reason we divide the message into two types is the receiver need to respond differently to these two types of message.
Structure Graph
Phase 1 Goal
Write client and server programs. In both client and server programs, there are two processes, parent process as Application Layer and child process as Datalink Layer. For a large file, the client program partitions the file into packets, send these packets one by one to the child process, datalink layer, then the child process send each packet to the server. Sever receives packets at Datalink Layer, sends them to Application Layer, and reassembles them into a single file. (Need help? Please refer to the attached file in my google drive folder, Help_Sess3_B05.pdf)
Useful resources
What's file and file handling in C
How to do file IO, text and binary, in C
Basic binary file manipulation function, e.g fseek, ftell
C, howto read binary file into buffer (set the size to be fileLen, and the nmenb to be 1)
What's process?
Intro to pipe
Interprocess commucation with pipes
pipe functions in c, pipe
pipe functions in c, popen and pclose
function read and write
process functions, fork
What's named pipe and how to create named pipe?
Solution to the "Permission Denied" exception when opening named pipe.
Need to specify the permission argument, mknod("pipe", S_IFIFO|S_IRUSR|S_IWUSR, 0)
Delete named pipe, i.e. unlink
How to define and declare a structure in C.
http://cprogramminglanguage.net/c-structure.aspx
No comments:
Post a Comment