Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

java.net.BindException: Address already in use

skidmarksMay 11 2011 — edited May 11 2011
On Windows XP I get no error. On Redhat Linux I get the 'Address already in use' error. I've logged off then logged on and started the software from the command line and in eclipse with the same results. The point of error is executed three times (diagnostic output below). The socket binding is for three different port (all with IPAddress 127.0.0.1) and this is the only time it is executed.

Any idea why the difference in the two OSs and how to fix it?
        if (socket.getPort() != 0 || !socket.isUnresolved()) {
            try {
                datagramSocket = new DatagramSocket(socket.getPort());
                if (!datagramSocket.isBound())
                    datagramSocket.bind(socket);
            } catch (SocketException e1) {
                Diagnostic.out(this.name + " " + socketName, Constants.DiagnosticMSG.SOCKETEXCEPTION);
                e1.printStackTrace();
                return null;
            }
        } else {
            System.out.format("Port = 0 (%d) or Socket resolved %b%n"
                             ,  socket.getPort()
                             , !socket.isUnresolved());
        }
Diagnostic Output.
The first two errors do not occur in XP. The last two errors are a consequence of the first two failing.
java.net.BindException: Address already in use
	at java.net.PlainDatagramSocketImpl.bind0(Native Method)
	at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:77)
	at java.net.DatagramSocket.bind(DatagramSocket.java:369)
	at java.net.DatagramSocket.<init>(DatagramSocket.java:228)
	at java.net.DatagramSocket.<init>(DatagramSocket.java:281)
	at java.net.DatagramSocket.<init>(DatagramSocket.java:253)
	at communication.SocketConnection.openSocket(SocketConnection.java:238)
	at communication.SocketConnection.init(SocketConnection.java:216)
	at communication.AbstractCommunication.superInit(AbstractCommunication.java:105)
	at communication.UDPCommunication.init(UDPCommunication.java:85)
	at server.UUTComm.init(UUTComm.java:81)
	at server.Server.init(Server.java:122)
	at execute.ExecuteCommand.init(ExecuteCommand.java:93)
	at parser.FileMode.main(FileMode.java:1196)
java.net.BindException: Address already in use
	at java.net.PlainDatagramSocketImpl.bind0(Native Method)
	at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:77)
	at java.net.DatagramSocket.bind(DatagramSocket.java:369)
	at java.net.DatagramSocket.<init>(DatagramSocket.java:228)
	at java.net.DatagramSocket.<init>(DatagramSocket.java:281)
	at java.net.DatagramSocket.<init>(DatagramSocket.java:253)
	at communication.SocketConnection.openSocket(SocketConnection.java:238)
	at communication.SocketConnection.init(SocketConnection.java:216)
	at communication.AbstractCommunication.superInit(AbstractCommunication.java:105)
	at communication.UDPCommunication.init(UDPCommunication.java:85)
	at communication.UDPCommunication.receive(UDPCommunication.java:99)
	at server.UUTComm.run(UUTComm.java:49)
java.net.BindException: Address already in use
	at java.net.PlainDatagramSocketImpl.bind0(Native Method)
	at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:77)
	at java.net.DatagramSocket.bind(DatagramSocket.java:369)
	at java.net.DatagramSocket.<init>(DatagramSocket.java:228)
	at java.net.DatagramSocket.<init>(DatagramSocket.java:281)
	at java.net.DatagramSocket.<init>(DatagramSocket.java:253)
	at communication.SocketConnection.openSocket(SocketConnection.java:238)
	at communication.SocketConnection.init(SocketConnection.java:216)
	at communication.AbstractCommunication.superInit(AbstractCommunication.java:105)
	at communication.UDPCommunication.init(UDPCommunication.java:85)
	at communication.UDPCommunication.send(UDPCommunication.java:127)
	at communication.UDPCommunication.send(UDPCommunication.java:151)
	at server.AbstractServerThread.run(AbstractServerThread.java:104)
	at java.lang.Thread.run(Thread.java:636)

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 8 2011
Added on May 11 2011
5 comments
1,700 views