Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(c) Given a coding at the server side that implementing multithreading task. Answer all questions based on the coding. 9 17 18 2. SKET4623 Network
(c) Given a coding at the server side that implementing multithreading task. Answer all questions based on the coding. 9 17 18 2. SKET4623 Network Programming, Final Exam Question 2 3: * @author kamalmy 4* TCPMultiThreads ServerSocket.java 5: / 6: package tcpultithreadsserversocket: 7: import java.io."; 8: import java.net.*: 10: public class TCPMulti ThreadsServerSocket 11: 12: public static void main(String args) throws Exception 13: Server Socket m_Server Socket = new ServerSocket(9999); 14: int id=0; 15: while (true) 16: Socket clientsocket-m_ServerSocket.accept(): Client Service Thread cliThread - new ClientService Thread(clientSocket, id++): cliThread.start(): 19) 20:) 21:) 22 23. class ClientService Thread extends Thread 24: Socket clientSocket; 25: int clientID=-1; 26: boolean running = true; 27 28: ClientService Thread(Socket s, int i) { 29: client Sockets: 30: clientID = 1; 31:1 32: 33 public void runo! 34 System.out.println("Accepted Client : D-" + clientID + - Address" + client Socket.getlnetAddress().getHostName()); 35: try { 36: BufferedReader in = new Buffered Reader(new InputStreamReader(clientSocket.getInputStream(): 37: Print Writer out = new Print Writer(new 38 39 40 41: 42 43. OutputStreamWriter(clientSocket.getOutputStream()); while (running) String clientCommand = in.readLine(): System.out.println("Client Says:" + clientCommand); if (clientCommand.equalsignoreCase "quit")) { running = false; System.out.print("Stopping client thread for client : + clientID): 44 } else { 45 out.println(clientCommand); 46 out.flush(); 47 } 48 } 49 } catch (Exception e) { 50: e.printStackTrace(); 51: 52: 53:) (1) What is the method used to create multithreaded in the given server side coding? (2 marks) (ii) What is the purposes of try and catch blocks? (4 marks) (iii) Give the possible output for the code in line 34: System.out.println("Accepted Client: ID -" + clientID + " Address -" + ellentSocket.getInetAddress().getHostName() (4 marks) (iv) What are the purposes of the Buffered Reader in line 36 and PrintWriter in line 372 (4 marks) (v) Why is outflush() in line 46 required in the code? (2 marks)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started