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?

Only administrators can bind ports smaller than port 1024.

Only administrators can bind ports smaller than port 1024.

Tried with different port numbers, like 2048, 2222, 9999 but there is still 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)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.