(14 points) write a TCP JAVA socket code to finish the following protocol: Cl) t
ID: 3831533 • Letter: #
Question
(14 points) write a TCP JAVA socket code to finish the following protocol: Cl) the client type in annual income and send it to server; 2) the server receives client type in income and then require the client to enter hisher dependent number, the his/her dependent number and send it to server; server will compute the client's according tax annual income 20%-number-dependents 1000. total tax in to: Assuming that the I address of server is: 198.98.98.98; the communication port is: 2700 First, draw the infrastructure diagram and flow-chart of client/server (5 points): Second, finish the codes as follows (9 points)Explanation / Answer
import java.io.*;
import java.net.*;
public final class MyClient {
public static void main(String args[]) throws IOException{
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("127.0.0.1", 2700);
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
outToServer.write(8000);
outToServer.flush();
System.out.println("Srever Asked: "+inFromServer.readLine());
outToServer.write(2);
outToServer.flush();
System.out.println("Total Tax :"+inFromServer.readLine());
}
}
import java.io.*;
import java.net.*;
public class MyServer {
public static void main(String[] args) throws IOException{
ServerSocket welcomeSocket = new ServerSocket(2700);
Socket connectionSocket = welcomeSocket.accept();
BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
int income = Integer.parseInt(inFromClient.readLine());
outToClient.writeUTF("Enter Dependent Number: ");
outToClient.flush();
int dependent = Integer.parseInt(inFromClient.readLine());
int tax = income*(income/100*20)-dependent*1000;
outToClient.writeUTF(""+tax);
outToClient.flush();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.