Click here to Skip to main content
15,906,265 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
"Error"
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.<init>(Unknown Source) 	at java.net.ServerSocket.<init>(Unknown Source) 	at server.main(server.java:20)


"Server Code"
Java
try
{
    ServerSocket ss = new ServerSocket(5555);
    System.out.println("Running....");
    
    Socket s = ss.accept();
    System.out.println("Accept");
    @SuppressWarnings("resource")
    FileInputStream fis = new FileInputStream("E:/Face");
    byte[]buffer = new byte[fis.available()];
    
    fis.read(buffer);
    ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
    oos.writeObject(buffer);
    oos.close();
    ss.close(); 
    s.close();
}
catch(IOException e) {
    e.printStackTrace();
}


}



"client code"

Java
try
{
    Socket s = new Socket("127.0.0.1",5555);
    ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
    try
    {
        byte[]buffer = (byte[]) ois.readObject();
        FileOutputStream oos = new FileOutputStream("/sdcard/DCIM");
        oos.write(buffer);
        
        oos.close();
    }

    catch(ClassNotFoundException e){
        e.printStackTrace();
        
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (OptionalDataException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    
    } 
    
    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    
    s.close();
}

catch(NumberFormatException e){
    e.printStackTrace();
} catch (UnknownHostException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
} catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}
Posted
Updated 25-Nov-14 22:41pm
v2
Comments
Richard MacCutchan 26-Nov-14 4:44am    
The error message is telling you what the problem is, and on which line it occurs. Check the code for repeatedly trying to bind the same address.
Member 10009139 27-Nov-14 6:19am    
thank you sir..
If you search the exception in Google, you will find many solutions. Have you tried any?
Member 10009139 27-Nov-14 6:19am    
thank you sir...
So, problem solved? If solved, then add the solution in the answer box, so that every visitor will come to know the answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900