Pages

Thursday, February 6, 2014

Lab 2 Questions 3,4a,5

3. The length of the link is 3600m and the propagation speed is 3*10^8 m/s.
   so 3600m/(3*10^8)=0.000036 m/s

distance/(propagation speed)+(file size)/(transmission rate)= ((3600m)/(3*10^8)) +((10MB)/(1Gbps))

=  0.000036 + 10MB/1Gbps

= 0.000036 + (10*10^6)/(1*10^9) = 0.010036secs for a 10MB to reach the end of a 3600m link with a 1Gbps rate

b) ((2m)/(3*10^8)) + ((10MB)/(10bps)) = 0.010036 + 1,000,000bps

0.010036 + 1,000,000bps = 1,000,000.010036secs for a 10MB to reach the end of 2m link with a 10bps rate

4. a) The pipe function needs these Headers. (in Ubuntu or LINUX platforms only)
#include <unistd.h>
Int pipe(int states[2]);
#define _GNU Source
#include <fcntl.h>
#include <unistd.h>
Int pipe2(int  state[2], int flags);
Functions and Variables
The pipe() function makes an one-directional path that is used for IPC. The fork function is very important in network communication, so the states variable will be determined by the fork function. Then, the states variable is used to implement two file function at the end of the pipe. When it is state[-1] it is for the error function. Then if it is state[0] then it means to fread the end of the pipe. Lastly if it is state[1], it means to write the end of the pipe. The information in the write function is buffered until it is used from the read function, so it needs a char buf[].  If it is successful in reading and write the end of the pipe then it returns 0 by default or does nothing, if not then it hits the error state.

5. fread and fwrite functions only need headers.
#include <stdio.h>
#imclude <stdlib.h>

Functions
Similar to OOP you need an object to be associated with the file stream functions. So the variable for that would be FILE *name. 
These FILE stream options are also accompanied by fopen and fclose functions (Used to open and close a file used in the program's scope)
fwrite() functions is used to permanently edit on the corresponding file that was opened. 
fread () functions is used to read or scan a file after it's opened depending on what it's looking for and holding that value for later purposes. 

Example:
#include <stdio.h>
#include <stdlib.h>
int main (int argc, char *argv[]){
FILE *object;
char buf[100];
size_t  sz;

/*Read Function*/
object  = fopen(“file.ext”, “r”);
if (object==NULL){
perror(“fopen”);
exit(1);
}
while(!feof(object))
{          sz= fread((void *) buf, 10, 1, object);
buf[9]=’\0’;
printf(“%s”,buf);     }
printf(“\n”);
fclose(object);

/*Write function*/
object1 = fopen(“file.ext”, “w”);
if (object1==NULL){
perror(“fopen”);
exit(1);
}
while(!feof(object1))
{          sz= fread((void *) buf, 10, 1, object1);
buf[9]=’\0’;
printf(“%s”,buf);     }
printf(“\n”);
fclose(object1);
return 0;
}
}





1 comment:

  1. good job Travis but you need to get your units right in q1

    ReplyDelete

Note: Only a member of this blog may post a comment.