I have written a simple client server application in java. When i try to run the client on the server I get the below exception. Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind at java.net.DualStackPlainSocketImpl.bind0(Native Method) at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source) at java.net.AbstractPlainSocketImpl.bind(Unknown Source) at java.net.PlainSocketImpl.bind(Unknown Source) at java.net.ServerSocket.bind(Unknown Source) at java.net.ServerSocket.(Unknown Source) at java.net.ServerSocket.(Unknown Source) at DateServer.main(DateServer.java:8)
I have added all the jar files checked everything how do I remove this exception to execute my code.
import java.util.Scanner;
import java.net.Socket;
class DateClient {
public static void main(String[] args) throws java.io.IOException {
String host = "localhost";
int port = Integer.parseInt("415");
Socket server = new Socket(host, port);
Scanner scan = new Scanner(server.getInputStream());
System.out.println(scan.nextLine());
}
}
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
class DateServer {
public static void main(String[] args) throws java.io.IOException {
ServerSocket s = new ServerSocket(415);
while (true) {
Socket incoming = s.accept();
System.out.println(incoming);
PrintWriter toClient = new PrintWriter(incoming.getOutputStream());
toClient.println(new Date());
toClient.flush();
incoming.close();
}
}
}