Em Andamento

Work: simulator File Transfer

Undergraduate Computer Engineering and Computer Management Basics of Programming - 1st Year - 1st Semester

1. Introduction

This paper serves as a practical assessment of the course Fundamentals of Programming Degree courses in Computer Engineering and Degree in IT Management Lusophone University of Humanities and Technologies. It aims at developing a program that represents a simulation system where you can observe the evolution of a file transfer. It is intended that students use the Java language and the theoretical concepts and practical imperative programming introduced during the semester.

2. Job description

From then presents the key topics to consider in development:

The simulation is performed to transfer a single file input in any format. The file should be copied byte by byte. The transfer can complete successfully, never complete or complete with errors. At the end of the transfer the MD5 values of the source file and destination file should be compared to detect errors. Should be considered the simulation time corresponds to real time. The unit of time that should be considered for all calculations is the nanosecond. The delay in the transfer of bytes is represented by a random variable vel forcing a transfer rate of 1 byte / nanosecond. During the transfer if the transfer rate remains at 1 byte / nanosecond during the transfer of 16 consecutive bytes, the transfer must be released and followed by an error message indicating Timeout: transfer aborted.

If during the transfer process is generated the value 1 for the random variable net, indicating the download is finished: Error connection: Transfer canceled. Another random variable err is determining whether or not an error in the last bytes of the downloaded file, in this case, a random number of bytes will not be copied, generating an error in comparing the MD5 values and the resulting error message: Error transferring file.

The program should show the beginning (time 0) state 0% transfer and the name, total bytes and MD5 value of the file transfer: random bytes will not be copied, generating an error in comparing the MD5 values and the resulting message : “Error downloading file”.

 

Ler [url removed, login to view], total bytes: 371

MD5:bf07bda199aeb9746a3085b2128f4e31

0%

The program initially determines the total bytes to transfer, the state calculates the transfer function of the number of bytes already transferred and is a process output. The state transfer is represented by the symbol “=” 5% for each completed and the values 20% , 40%, 60%, 80%, 100%, according to the state. The value 100% represents the end of the transfer:

0%===20%===40%===60%===80%===100%

The output should also show the name of the file destination and the number of bytes and MD5 value after transfer and total time used (in seconds) and its speed in KBytes / second:

The simulation ends when one of the following conditions are met:

- The file was transferred successfully;

- The file transfer was canceled;

- Detected error downloading file;

- connection error detected

3. Arguments program

The program to develop ([url removed, login to view]) must accept as arguments the following values:

$> java TransferirFicheiro <f_origem> <f_destino> [--lim] [--net] [--err]

f_origem : source file name to transfer

f_destino: filename destination;

--lim : introduces error when verifying the transfer of 16 consecutive bytes to 1 byte / nanosecond

--net : introduces randomness connection error;

--err : introduces the randomness of error transfer

To display help on using the program, using the argument - help:

$> java TransferirFicheiro –-help

--help: support with the program

Arguments f_origem and f_destino are required. The absence of at least one of the arguments - lim, - net - or err imply that there is no simulation in this case the file will be transferred without the randomness of the data transfer speed. Is it possible to use any of the arguments - lim, - net - or err to start the simulation.

4. Examples of implementation

Take the example of the program, without the use of arguments:

$> java TransferirFicheiro

****************************************************************************

** Simulador de transferencia de ficheiros **

** **

** Este programa necessita de argumentos para executar, de modo a obter **

** uma lista de argumentos disponíveis, utilize: **

** java TranferirFicheio -–help **

** **

Take the example of using the argument - help:

$> java TransferirFicheiro –-help

****************************************************************************

** Simulador de transferencia de ficheiros **

** **

** Utilizacao: **

** java TransferirFicheiro <f_origem> <f_destino> [--lim] [--net] [-–err] **

****************************************************************************

f_origem : nome do ficheiro origem a transferir

f_destino: nome do ficheiro destino

--lim : introduz erro de tempo limte excedido

--net : introduz erro de conexao

--err : introduz erro de transferencia

Consider the use of [url removed, login to view] file containing the following text:

People are often concerned about measuring the maximum data throughput rate of a

communications link or network access. A typical method of performing a measurement is to

transfer a 'large' file and measure the time taken to do so. The throughput is then calculated by

dividing the file size by the time to get the throughput in megabits, kilobits, or bits per second.

NOTE: In a text file, each character or blank space corresponds to a byte

Take the example of file transfer [url removed, login to view] [url removed, login to view] to the file without using simulation:

$> java TransferirFicheiro [url removed, login to view] [url removed, login to view]

Ler [url removed, login to view], total bytes: 371

MD5:bf07bda199aeb9746a3085b2128f4e31

Transferir para destino: [url removed, login to view]

0%===20%===40%===60%===80%===100%

MD5:bf07bda199aeb9746a3085b2128f4e31

Transferencia concluida com sucesso.

Total bytes: 371

Tempo total (segundos): [url removed, login to view]

Velocidade (KBytes/segundo): [url removed, login to view]

Take the example of file transfer the file to [url removed, login to view] [url removed, login to view] using simulation:

$> java TransferirFicheiro [url removed, login to view] [url removed, login to view] --lim

Ler [url removed, login to view], total bytes: 371

MD5:bf07bda199aeb9746a3085b2128f4e31

Transferir para destino: [url removed, login to view]

0%===20%===40%===60%=

Tempo limite excedido: transferencia cancelada

$> java TransferirFicheiro [url removed, login to view] [url removed, login to view] –-net

Ler [url removed, login to view], total bytes: 371

MD5:bf07bda199aeb9746a3085b2128f4e31

Transferir para destino: [url removed, login to view]

0%===20%===40%===60%===80%==

Erro de conexao: transferencia cancelada

$> java TransferirFicheiro [url removed, login to view] [url removed, login to view] --err

Ler [url removed, login to view], total bytes: 371

MD5:bf07bda199aeb9746a3085b2128f4e31

Transferir para destino: [url removed, login to view]

0%===20%===40%===60%===80%===100%

MD5:e78c66e7087e9702d803ffce0df63ae6

Erro ao transferir ficheiro.

Total bytes: 369

Tempo total (segundos): [url removed, login to view]

Velocidade (KBytes/segundo): [url removed, login to view]

$> java TransferirFicheiro [url removed, login to view] [url removed, login to view] --lim –-net --err

Ler [url removed, login to view], total bytes: 371

MD5:bf07bda199aeb9746a3085b2128f4e31

Transferir para destino: [url removed, login to view]

0%===20%===40%===60%===80%===100%

MD5:bf07bda199aeb9746a3085b2128f4e31

Transferencia concluida com sucesso.

Total bytes: 371

Tempo total (segundos): [url removed, login to view]

Velocidade (KBytes/segundo): [url removed, login to view]

Note that the simulation can produce errors (or not) depending on the random variables. A simulation can never produces errors, but the transfer speed is always random.

 

5. Random Variables

In this simulation the transfer speed (vel), the error of connection (net) and transfer error (err) are modeled by random variables. A random variable follows a statistical law (density function of probability) that defines what values the variable can take on average and with what probability.

For speed (vel) a random number 0 or 1 is generated. A value of 1 represents the delay of 1 nanosecond in the transfer of 1 byte, value 0 indicates the absence of delays. In every moment of transfer of 1 byte can be delayed or not.

For the connection error (net) a random number between 0 and 100000 is generated. A value of 1 represents the existence of error in the connection, any other value indicates the absence of errors. The existence of at least one error determines the end of the transfer. In every moment of transfer of 1 byte can be or not connection error.

For the transfer error (err) a random number is generated between 0 and 2. A value of 0 indicates no errors, a value of 1 or 2 indicates the number of characters that are not copied to the destination file, causing transfer error. The error should be detected at the end of the transfer by comparing the MD5 values of the source and destination files. This random variable is generated before the transfer.

How to generate values of random variables? The Random class allows you to create random number generators uniform. The speed (vel) can be generated with the statement:

vel = (int) [url removed, login to view]([url removed, login to view]()*2) + 0;

The connection error (net) can be generated with the statement:

net = (int) [url removed, login to view]([url removed, login to view]()*100000) + 0;

The transfer error (err) can be generated with the statement:

err = (int) [url removed, login to view]([url removed, login to view]()*3) + 0;

6. Streaming bytes

The programs use the streaming (streaming) of bytes to perform the input and output byte (8 - bit). All classes of streaming bytes descendants of InputStream and OutputStream classes. To demonstrate the operation of the stream of bytes we will focus on input / output applied to files using FileInputStream and FileOutputStream. Let's examine the class CopiaBytes that uses stream of bytes to copy the file to the file [url removed, login to view] [url removed, login to view], one byte at a time:

 

import [url removed, login to view];

import [url removed, login to view];

import [url removed, login to view];

public class CopiaBytes {

public static void main(String[] args) throws IOException {

FileInputStream in = null;

FileOutputStream out = null;

in = new FileInputStream("example.txt");

out = new FileOutputStream("outexample.txt");

int i;

while ((i = [url removed, login to view]()) != -1) {

[url removed, login to view](i);

}

if (in != null)

[url removed, login to view]();

if (out != null)

[url removed, login to view]();

}

}

The CopiaBytes spends most time in a simple cycle that reads the input stream and writes the output stream, one byte at a time, as shown following:

Figura 1: Exemplo de I/O byte stream

Note that read () returns an integer value. If the input is a stream of bytes, why the read () does not return a byte value? Using an int as return type allows read () use -1 to indicate that reached the end of streaming.

The close () is used to close the stream input and output. Close a stream when it is most needed is important. A possible error is that the CopiaBytes be unable to open the files. When this happens the variable corresponding to the streaming file is never changed from its initial value null, because of this the CopiaBytes ensures that each variable contains streaming information before invoking the close ().

The CopiaBytes looks like a normal program, but actually represents an input / output low-level. If the file transfer was always in text format, containing only characters, the best approach would be to use streaming characters. There are also other streams for the most complicated types of data. The stream of bytes to be used for the I / O more primitive. Why talk about the stream of bytes? For all other types of streaming are constructed from the stream of bytes. The stream of bytes to transfer files in any format.

7. Speed enforcement

The speed of the program can be controlled by the instruction [url removed, login to view] (). This statement causes the program to stop running for some time. The instruction takes two parameters to control the delay: milliseconds (long type) and nanosecond (type int). In the example below, the statement causes the program is idle for 5000 milliseconds (5 seconds) and 100 nanoseconds:

[url removed, login to view](5000, 100)

In the following example (Velocidade0) the program calculates the time of execution of a loop that prints 1500 integers:

public class Velocidade0 {

public static void main(String[] args) throws Exception {

long tempoInicio = [url removed, login to view]();

for(int i=1;i<=1500;i++ ){

[url removed, login to view](i);

}

long tempo = [url removed, login to view]() - tempoInicio;

[url removed, login to view]("segundos: %.4f%n",tempo/1000.0);

}

}

See the runtime: [url removed, login to view] segundos

$> java Velocidade0

..

1494

1495

1496

1497

1498

1499

1500

segundos: [url removed, login to view]

In the following example (Velocidade1) the program performs the same previous cycle, is now introducing a delay of 1 nanosecond for each cycle using the [url removed, login to view] statement (0.1):

public class Velocidade1 {

public static void main(String[] args) throws Exception {

long tempoInicio = [url removed, login to view]();

for(int i=1;i<=1500;i++ ){

[url removed, login to view](0,1); //retardamento 1 nanosegundo

[url removed, login to view](i);

}

long tempo = [url removed, login to view]() - tempoInicio;

[url removed, login to view]("segundos: %.4f%n",tempo/1000.0);

}

}

See the runtime: [url removed, login to view] segundos

$> java Velocidade1

..

1494

1495

1496

1497

1498

1499

1500

segundos: [url removed, login to view]

Is a clear difference in run time, influenced by education [url removed, login to view]

8. MD5 (Message-Digest algorithm 5)

MD5 (Message-Digest algorithm 5) is a hash algorithm 128-bit unidirectional developed by RSA Data Security, and widely used by software protocol with point-to-peer (P2P) to verify integrity of files and logins.

Being a one-way algorithm, an MD5 hash can not be turned back to the file that caused it. MD5 can be used to verify the integrity of a file through, a program that creates the hash of a file. This can be very useful for Transfrências large files to P2P programs that build the file using bits and are subject to the same corruption. How login authentication is used in several UNIX operating systems and many sites with authentication.

The following example ObterMD5 to create the MD5 hash of the file [url removed, login to view]:

 

import java.io.*;

import java.security.*;

import java.math.*;

public class ObterMD5{

public static void main(String[] args) throws Exception {

MessageDigest digest = [url removed, login to view]("MD5");

File ficheiro = new File("example.txt");

InputStream entrada = new FileInputStream(ficheiro);

byte[] buffer = new byte[8192];

int ler = 0;

while( (ler = [url removed, login to view](buffer)) > 0) {

[url removed, login to view](buffer,0,ler);

}

byte[] md5Bytes = [url removed, login to view]();

BigInteger bigInt = new BigInteger(1,md5Bytes);

String saida = [url removed, login to view](16);

[url removed, login to view]("MD5: " + saida);

}

}

O output corresponde ao hash MD5 do ficheiro [url removed, login to view]

$> java ObterMD5

MD5: bf07bda199aeb9746a3085b2128f4e31

In the case of transfer of files, the MD5 hash of the source and destination files must be identical, otherwise indicates data corruption.

9. Tests

In order to verify the proper functioning of the code developed is to use the file [url removed, login to view] found at Netlab ([url removed, login to view]) and the following arguments to the program:

Test 1:

$> java TransferirFicheiro [url removed, login to view] [url removed, login to view]

Test 2:

$> java TransferirFicheiro [url removed, login to view] [url removed, login to view] –-lim –-net –err

Test 3:

$> java TransferirFicheiro [url removed, login to view] [url removed, login to view] –err

 

10. Report

Besides the software developed should also write a report of the practical work. The report must contain the following items:

- Introduction

- Application Architecture

- Flowchart

- Description of tests carried out aplicacao

11. Delivery

The delivery should take place in the portal moodle (ULHT) within the time allowed, with details on number and name of the student group that performs the work. Deliveries will not be accepted after the deadline stipulated.

Upon delivery, must send a single zip file containing the following:

a) Report (required) PDF

b) java Code developed under the name [url removed, login to view]

c) the bytecode version of the code, named TransferirFicheiro. class;

if possible the comment code for possible questions from the teacher to parts of the code.

Habilidades: Java

Ver mais: simulador md5, file transfer simulator, data transfer simulation java, bit transfer simulation java, java file transfer random, file transfer simulation java, transfer file java simulation, practical file transfer java, md5 simulation, md5 simulator, error transferring file, transferring integers simulator, java using bits transfer, write communications, work login, work close, programming important, education important, computer programming important, job sites actually work, java programming used, computer programming used, variable computer programming, algorithm math

Acerca do Empregador:
( 0 comentários ) lisbon, Portugal

ID do Projeto: #587072

Premiar a:

sirusbmf

I can do this work.

$40 USD em 1 dia
(0 Avaliações)
0.0

9 freelancers estão ofertando em média $78 para este trabalho

pawel100

Hello, I'm interested in your project, Please check PMB for more details.

$40 USD in 4 dias
(15 Comentários)
4.4
talluriamara

i had experience in developing these kind of projects.i am good at java.please give me a chance.

$40 USD in 3 dias
(3 Comentários)
4.0
agilepro

Sir, I have already done this type of project. I can fully complete your job. Hope you will make the deal with me.

$50 USD in 2 dias
(2 Comentários)
2.7
bogdartysh

Time & price depends on the needed volume of the report

$35 USD in 5 dias
(2 Comentários)
2.0
webdevelopers05

ready to start the program.

$69 USD in 4 dias
(0 Comentários)
0.0
mages1ul

4 days is the maximum to deliver.

$75 USD in 4 dias
(0 Comentários)
0.0
silverlean

i will submit it in ten days

$100 USD in 10 dias
(0 Comentários)
0.0
Raghucan

Indeed, this is a good project to work on. We will do this for you with 100% satisfaction in quality and time.

$250 USD in 3 dias
(0 Comentários)
0.0