Question Write TCP client and server that can communicate to each other saying “Hello I am client and My id is 1” and “Hello I am server. Your received id is 1” The ID of the client should be only a single-digit i.e from 0 to 9 Run one client and server on same machine Your server should be in running state infinitely and should not terminate after serving one client only. The clients will keep on coming one by one and server will keep on serving them unless terminated intentionally. Sample Test Bench – Client1 sends : “Hello I am client and My id is 1” – Client2 sends: “Hello I am client and My id is 2” – Server response on client1: “Hello I am server. Your received id is 1” – Server response on client2: “Hello I am server. Your received id is 2”

RMNJDM The Asker · Computer Science

Write TCP client and server that can communicate to each other saying
“Hello I am client and My id is 1” and “Hello I am server. Your received id is 1”
The ID of the client should be only a single-digit i.e from 0 to 9
Run one client and server on same machine
Your server should be in running state infinitely and should not terminate
after serving one client only. The clients will keep on coming one by one
and server will keep on serving them unless terminated intentionally.
Sample Test Bench
– Client1 sends : “Hello I am client and My id is 1”
– Client2 sends: “Hello I am client and My id is 2”
– Server response on client1: “Hello I am server. Your received id is 1”
– Server response on client2: “Hello I am server. Your received id is 2”

More
Community Answer
UN69DJ

Answer: Give me a thumbs up if you like my work !!! I have written the below code based on your requirements. The below code has no-error and it is working perfectly. I have also attached the Output Screenshot that I got by running the below program. Output Screenshot: akash-11140@akash-11140: / Desktop$ javac Server.javaakash-11140@akash-11140: /Desktop$ java ServerServer Started Running...Hello I am client and My id is 1 akash-11140@akash-11140: /Desktop$ javac Client.javaakash-11140@akash-11140: / Desktop$ java ClientHello I am server. Your received id is 1akash-11140@akash-11140: / Desktop$   Code: File Name : Server.java import java.io.*;   import java.net.*;   public class Server  {       public static void main(String[] args)     {       try     {           ServerSocket ss=new ServerSocket(6666);          System.out.println("nServer Started Running...");                  while(true)         {                         Socket s=ss.accept();                          DataInputStream dis=new DataInputStream(s.getInputStream());               String  str=(String)dis.readUTF();                            String[] Client_Message=str.split(" ");             int size=Client_Message.length;                          System.out.println(str);                          int id=Integer.parseInt(Client_Message[size-1]);                            DataOutputStream dout=new DataOutputStrea ... See the full answer