[英]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: 对于基于tcp的套接字,我得到的地址为192.168.0.2,但是当我使用udp时:
serverSocket = new DatagramSocket(new InetSocketAddress(InetAddress.getLocalHost(), 0));
I always get a null or 0.0.0.0 address binding. 我总是得到一个null或0.0.0.0地址绑定。 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.
我希望将套接字绑定到192.168.0.2,以便我的其他服务器可以与其通信。
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 ? 您的操作系统是什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.