I have this client/server connection using serversockets in java.
I am able to connect multiple clients to it but whenever I close one of them, the server sockets throws an error.
Java Code:
Exception in thread "main" java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
        at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
        at sun.nio.cs.StreamDecoder.read(Unknown Source)
        at java.io.InputStreamReader.read(Unknown Source)
        at java.io.BufferedReader.fill(Unknown Source)
        at java.io.BufferedReader.readLine(Unknown Source)
        at java.io.BufferedReader.readLine(Unknown Source)
        at client.Client.main(Client.java:22)
What can I do to fix this? Whenever this happens, it will throw and error in the client too.
Java Code:
Exception in thread "main" java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(Unknown Source)
        at java.net.SocketInputStream.read(Unknown Source)
        at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
        at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
        at sun.nio.cs.StreamDecoder.read(Unknown Source)
        at java.io.InputStreamReader.read(Unknown Source)
        at java.io.BufferedReader.fill(Unknown Source)
        at java.io.BufferedReader.readLine(Unknown Source)
        at java.io.BufferedReader.readLine(Unknown Source)
        at client.Client.main(Client.java:22)
Client.java (Client side)
Java Code:
package client;

import java.io.*;
import java.net.*;

class Client {
    public static void main(String argv[]) throws Exception {
        String sentence;
        String modifiedSentence;
        int number = 0;
      while(true){
        BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));

        Socket clientSocket = new Socket("localhost", 2343);

        DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
        BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));

        System.out.println("Ready");
        sentence = "HI "+ number;
        out.writeBytes(sentence + '\n');
        modifiedSentence = in.readLine();
        System.out.println(modifiedSentence);
        number++;
       }
    }
}
Server.java (Server side)
Java Code:
package server;

import java.io.*;
import java.net.*;

public class Server {
	
	public static void main(String args[]) throws Exception {
	String clientSentence;
	String cap_Sentence;
	ServerSocket my_Socket = new ServerSocket(2343);
	
		while(true) {
			Socket connectionSocket = my_Socket.accept();
			BufferedReader in = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
			DataOutputStream out = new DataOutputStream(connectionSocket.getOutputStream());
			clientSentence = in.readLine();
			System.out.println("Received: " + clientSentence);
			cap_Sentence = "Received:" +  clientSentence + '\n';
			out.writeBytes(cap_Sentence);
			Thread.sleep(500);
		}
	}
}

Thanks in advance!