LocalDevice.initialize() throws exception
-
When I run the code mentioned at the last following errors are received
Exception in thread "main" java.net.BindException: Address already in use (Bind failed)
at java.base/java.net.PlainDatagramSocketImpl.bind0(Native Method)
at java.base/java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:131)
at java.base/java.net.DatagramSocket.bind(DatagramSocket.java:394)
at java.base/java.net.DatagramSocket.<init>(DatagramSocket.java:244)
at com.serotonin.bacnet4j.npdu.ip.IpNetwork.initialize(IpNetwork.java:169)
at com.serotonin.bacnet4j.transport.DefaultTransport.initialize(DefaultTransport.java:186)
at com.serotonin.bacnet4j.LocalDevice.initialize(LocalDevice.java:316)The code is:
public class App
{
public static void main( String[] args ) throws Exception
{
final int port = 47808;
IpNetwork network;
network = new IpNetworkBuilder()
.withSubnet("192.168.1.0", 24)
.withLocalBindAddress("192.168.1.107")
.withPort(port)
.build();
Transport transport = new DefaultTransport(network);
LocalDevice localDevice = new LocalDevice(1000, transport);
try {
localDevice.initialize();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}The same exception is also received for localDevice.initialize(RestartReason.coldstart);
Please provide solution.
Regards,
Kishore -
Hi Kishore,
The "address already in use" exception means some other application has already bound the port. Perhaps you have another BACnet application running on this computer? Perhaps your application is already running?
-
Hello,
There is no other application running. When I terminate the server no response this local Device. But every time at the inititalize() command, I am getting exception.
Further the values of device object, services that are modified and objects that are added not reflected in the local device. That is from the 3rd party client if I send the ReadProperty request, only the default values are returned and not the values that are set in the code. Probably I will raise another ticket with the code which help us to solve two different issues.
Regards,
Kishore -
Well, the exception means that something else has already bound the port, so you could figure out what has the port with some netstat commands probably. Or you could restart your machine to clear whatever it is (unless it starts at startup).
If you have a third party application able to read from the port, and you cannot run the code now, wouldn't that suggest some application is running on the port already?
-
Yes, you are right. somehow port is blocked. After killing the process and the running the app, initialize() command was executed successfully.
Thanks.
Regards,
Kishore