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)