开发者

bind datagramsocket to inetaddress

开发者 https://www.devze.com 2023-01-17 00:12 出处:网络
When I use serverSocket = serverChannel.socket(); serverSocket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0));

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

精彩评论

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