Reputation: 1065
When I use
serverSocket = serverChannel.socket();
serverSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));
for tcp-based sockets, I get given the address 192.168.0.2, but when I use udp:
serverSocket = new DatagramSocket(new InetSocketAddress(InetAddress.getLocalHost(), 0));
I always get a null or 0.0.0.0 address binding. What is going on here exactly? I want the socket to be bound to 192.168.0.2 so that my other servers can communicate with it.
Upvotes: 1
Views: 1946
Reputation: 24630
Runs for me. What get you with this:
InetSocketAddress in = new InetSocketAddress(InetAddress.
getLocalHost(), 0);
System.err.println(in);
serverSocket = new DatagramSocket(in);
What is your OS ?
Upvotes: 1