This simple code is showing the following error.
import java.io.IOException;
import java.net.*;
public class Server {
public static void main(String[] args) throws IOException {
DatagramSocket ds = new DatagramSocket(999, InetAddress.getByName("192.168.1.102"));
ds.send(new DatagramPacket(new byte[10], 10));
}
}
Error:
Exception in thread "main" java.net.BindException: Cannot assign requested address: Cannot bind
at java.net.PlainDatagramSocketImpl.bind0(Native Method)
at java.net.PlainDatagramSocketImpl.bind(Unknown Source)
at java.net.DatagramSocket.bind(Unknown Source)
at java.net.DatagramSocket.<init>(Unknown Source)
at java.net.DatagramSocket.<init>(Unknown Source)
at Server.main(Server.java:6)
But, why its not working? IP 192.168.1.102 is live and connected in a wireless home network via router.
And if it use the IP of the pc I am working on, it shows me the following error,
Exception in thread "main" java.lang.NullPointerException: null address || null buffer
at java.net.PlainDatagramSocketImpl.send(Native Method)
at java.net.DatagramSocket.send(Unknown Source)
at Server.main(Server.java:7)
Can anyone explain what is the meaning of these errors?