开发者

bind datagramsocket to inetaddress

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 ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜