Here is my code of project -->importjava.io.*;importjava.net.*;importjava.util.concurrent.*;publicclassTCPPacketServer{privatestaticintport=1024;privatestaticExecutorServicepool=Executors.newFixedThreadPool(10);publicstaticvoidmain(String[]args){try{ServerSocketserverSocket=newServerSocket(port);System.out.println(``Openingport…'');while(true){SocketclientSocket=serverSocket.accept();pool.execute(newClientHandler(clientSocket));}}catch(IOExceptione){e.printStackTrace();}}privatestaticclassClientHandlerimplementsRunnable{privateSocketclientSocket;publicClientHandler(Socketsocket){this.clientSocket=socket;}publicvoidrun(){try{PrintStreamps=newPrintStream(clientSocket.getOutputStream());while(true){InputStreamis=clientSocket.getInputStream();byte[]buffer=newbyte[1024];intbytesRead=is.read(buffer);if(bytesRead>0){ByteArrayInputStreambais=newByteArrayInputStream(buffer,0,bytesRead);ObjectInputStreamois=newObjectInputStream(bais);Packetpacket=(Packet)ois.readObject();System.out.println(``RecievingfromclientsPacketsserialNo#''+packet.getSerialNo()+``\nandpacketsDatais``+packet.getData().toUpperCase());if(packet.getData().toUpperCase().equals(``CLOSE'')){break;}PacketresponsePacket=newPacket(packet.getSerialNo(),``PacketSerialNo#''+packet.getSerialNo()+``isreceived'');ByteArrayOutputStreambaos=newByteArrayOutputStream();ObjectOutputStreamoos=newObjectOutputStream(baos);oos.writeObject(responsePacket);byte[]responseBuffer=baos.toByteArray();ps.write(responseBuffer);}}ps.close();clientSocket.close();}catch(IOException|ClassNotFoundExceptione){e.printStackTrace();}}}}importjava.io.*;importjava.net.*;publicclassTCPPacketClient{privatestaticString[]output={``Enterthedatapacket:``};publicstaticvoidmain(String[]args){try{Socketsocket=newSocket(``localhost'',1024);PrintStreamps=newPrintStream(socket.getOutputStream());BufferedReaderinput=newBufferedReader(newInputStreamReader(System.in));Stringline=``'';intserialNo=1;while(!line.toUpperCase().equals(``CLOSE'')){System.out.print(output[0]);line=input.readLine();Packetpacket=newPacket(serialNo++,line);ByteArrayOutputStreambaos=newByteArrayOutputStream();ObjectOutputStreamoos=newObjectOutputStream(baos);oos.writeObject(packet);byte[]buffer=baos.toByteArray();ps.write(buffer);InputStreamis=socket.getInputStream();byte[]responseBuffer=newbyte[1024];intbytesRead=is.read(responseBuffer);if(bytesRead>0){ByteArrayInputStreambais=newByteArrayInputStream(responseBuffer,0,bytesRead);ObjectInputStreamois=newObjectInputStream(bais);PacketresponsePacket=(Packet)ois.readObject();System.out.println(``FROMSERVER:``+responsePacket.getData());}}ps.close();socket.close();}catch(IOException|ClassNotFoundExceptione){e.printStackTrace();}}}importjava.io.Serializable;publicclassPacketimplementsSerializable{privateintserialNo;privateStringdata;publicPacket(intserialNo,Stringdata){this.serialNo=serialNo;this.data=data;}publicStringgetData(){returndata;}publicintgetSerialNo(){returnserialNo;}}importjava.io.*;importjava.net.*;publicclassMTServer{publicstaticvoidmain(String[]args){try{ServerSocketserverSocket=newServerSocket(8080);System.out.println(``Waitingforclientrequest…'');Socketsocket=serverSocket.accept();System.out.println(``Newclientispopup!``);BufferedReaderbr=newBufferedReader(newInputStreamReader(socket.getInputStream()));PrintStreamps=newPrintStream(socket.getOutputStream());Stringresponse;while(true){System.out.print(``Server:``);Stringline=newBufferedReader(newInputStreamReader(System.in)).readLine();ps.println(line);response=br.readLine();if(response.equals(``CLOSE'')){break;}System.out.println(``Clients:``+response);}ps.close();br.close();socket.close();System.out.println(``Endofconversation'');}catch(IOExceptione){System.err.println(e);}}}importjava.io.*;importjava.net.*;publicclassClients{publicstaticvoidmain(String[]args){try{Socketsocket=newSocket(``localhost'',8080);System.out.println(``Requestsentsuccessfully'');BufferedReaderbr=newBufferedReader(newInputStreamReader(socket.getInputStream()));PrintStreamps=newPrintStream(socket.getOutputStream());Stringresponse;while(true){response=br.readLine();System.out.println(``Server:``+response);System.out.print(``Clients:``);Stringline=newBufferedReader(newInputStreamReader(System.in)).readLine();ps.println(line);if(line.equals(``CLOSE'')){break;}}ps.close();br.close();socket.close();System.out.println(``Endofconversation'');}catch(IOExceptione){System.err.println(e);}}}
Here is code grading-->PROGRAMMING TECHNOLOGIES AND EDUCATIONAL
PRACTICE
Project - 3
GRADING POLICY
Part - 1
Implementation (50%)
a. Basic Functionality (35%)
● The program establishes a connection between the client and server using sockets,
allowing it to send data packets along with their corresponding serial numbers.
● The server converts the received message to uppercase.
● Use getInputStream() method to obtain a handle to the socket stream.
● Use getOutputStream() method to send out the data through the socket stream.
● Use the BufferedReader method to read from the keyboard the data (Packet) that needs to
be sent to the server.
● The server sends the converted message back to the client (FROM SERVER: Packet
SerialNo# is received).
● The client terminates the connection upon sending a "CLOSE" message.
b. Error Handling and Exceptional Cases (10%)
● The program handles exceptions and error conditions appropriately.
● Handling of unexpected client disconnections.
a. Readability and Maintainability (5%)
● The code is well-structured, properly indented, and easy to understand.
● Descriptive variable and method names are used.
● The code follows the instructions.
Part - 2
Implementation (50%)
a. Basic Functionality (35%)
● The program successfully establishes a client-server connection using sockets.
● The client application generates a socket and connects it to the server.
● The server constructs a socket object to facilitate communication.
● The client and server can communicate by writing to and reading from the socket using
the java.net package.
b. Message Sending (5%)
● The server uses PrintStream ps = new PrintStream(socket.getOutputStream());” to send a
message to Client from Server.
● The message sent by the server is received correctly by the client.
c. Message Reception (5%)
● The client uses BufferedReader br = new BufferedReader(new
InputStreamReader(socket.getInputStream())); to receive the message from Client
● The received message is read and processed correctly by the client.
c. Error Handling and Exceptional Cases (5%)
● The program handles exceptions and error conditions appropriately.
● Handling of unexpected disconnections.
---
Your task is grading my project