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 开发者_StackOverflow社区to be bound to 192.168.0.2 so that my other servers can communicate with it.
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 ?
精彩评论