0
Good afternoon, I am attending ADS EAD and I say that I have a lot of difficulty learning, I have this job to deliver and I do not know how to solve. The teacher said it’s to use this structure and change little to answer the questions. Can anyone help me understand how to answer these questions?
- In unit 1 and 2 it was seen in detail what are distributed systems and a simple implementation of the Client-Server model with sockets in Java, as codes below:
/******* SERVER CLASS START
Server:
(socketServer file.java)
java.io.Objectoutputstream import;
import java.net.Serversocket;
import java.net.Socket;
public class socketServer {
public static void main(String args[]){
try {
//iniciar um ServerSocket na porta 12345
ServerSocket server = new ServerSocket(12345);
System.out.println("Servidor iniciado na porta 12345");
while(true) {
// o método accept() bloqueia a execução até que
// o servidor receba um pedido de conexão
Socket client = server.accept();
//Imprime IP do cliente que solicitou acesso
System.out.println("Cliente conectado: "
+ client.getInetAddress().getHostAddress());
//cria uma estrutura de envio de objeto
ObjectOutputStream send = new ObjectOutputStream(client.getOutputStream());
send.writeObject("Bem vindo ao servidor");
send.flush();
send.close();
client.close();
}
} catch (Exception e) {
System.out.println("Erro: " + e.getMessage());
}
}
}
/***** END OF SERVER CLASS
/***** BEGINNING OF THE CUSTOMER CLASS
Client:
(socketClient.java file)
java.io.Objectinputstream import;
import java.net.Socket;
public class socketClient {
public static void main(String[] args) {
try {
// cria um socket cliente com o endereço e porta destino
Socket client = new Socket("localhost", 12345);
//cria uma estrutura de recebimento de objetos
ObjectInputStream receive = new ObjectInputStream(client.getInputStream());
String response = (String) receive.readObject();
System.out.println("Mensagem: " + response);
receive.close();
System.out.println("Conexão encerrada");
} catch (Exception e) {
System.out.println("Erro: " + e.getMessage());
}
}
}
/***** END OF CUSTOMER CLASS
O exemplo, acima apresentado, implementa a comunicação entre cliente e servidor por meio de sockets. O cliente se conecta no servidor, esperando um objeto (uma string nesse caso). Enquanto que o servidor está aguardando conexões de clientes (um por vez) e enviando um objeto (String).
Task:
Baseado no exemplo apresentado,
a) implement a client-server communication where the client sends an array of integer numbers to the server (Required).
b) The server, in turn, takes this array, and prints it backwards (Required).
c) All classes must have the project creator at the top of the class (Required).
d) You must comment on each function or code snippet with your words (Required).
The project must be created in Java in the Eclipse IDE must be exported and posted in the activity (in the eclipse choose menu File > Export >General> Archive File>Select Project - attention to the choice of Root Project, and to the destination location of your ZIP - use the Browse... button next to the field To Archive file).
This exported . zip must be shipped in this task,