+ -
当前位置:首页 → 问答吧 → 通DatagramSocket绑定不了对方端口的问题

通DatagramSocket绑定不了对方端口的问题

时间:2010-07-22

来源:互联网

现在的问题是这样的,对方把接收到的数据发送到其本机的11012端口上,我现在想通过DatagramSocket 接收的报文,

        public static void main(String args[]) throws UnknownHostException{
                InetAddress ip =InetAddress.getByName("10.11.1.22";
                System.out.println(ip);
                try {
                        ds =new DatagramSocket(ClientPort,ip);
                        while(true){
                                ds.receive(new DatagramPacket(buff,buff.length));
                                System.out.println("客户端收到了服务端的信息:"+new String(buff,0,buff.length));
                        }
                } catch (SocketException e) {
                        e.printStackTrace();
                }catch(IOException e){
                        e.printStackTrace();
                }
        }

运行之后,结果报如下错误,大家帮忙分析一下:
java.net.BindException: Cannot assign requested address: Cannot bind
        at java.net.PlainDatagramSocketImpl.bind0(Native Method)
        at java.net.PlainDatagramSocketImpl.bind(PlainDatagramSocketImpl.java:82)
        at java.net.DatagramSocket.bind(DatagramSocket.java:36
        at java.net.DatagramSocket.<init>(DatagramSocket.java:210)
        at java.net.DatagramSocket.<init>(DatagramSocket.java:261)
***********************

作者: HF.SKY000   发布时间: 2010-07-22

这个论坛里怎么回复的人很少呀。

作者: HF.SKY000   发布时间: 2010-07-23