0

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?

Edited by iamcreasy: n/a

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by iamcreasy
0

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)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.