0
protected String doInBackground(String... f_url) {
        int count;

        byte [] ip_bytes = new byte[] {(byte)192,(byte)168,(byte)1,(byte)100};
        try {
            InetAddress address = InetAddress.getByAddress(ip_bytes );

          byte buffer[] = new byte[2000];

                    DatagramPacket p = new DatagramPacket(buffer, buffer.length, address, port);
                    try {
                    DatagramSocket ds = new DatagramSocket(port);
                    Log.d("..........","Perfect Binding .... Waiting for Data");
                    ds.receive(p);
                    publishProgress(""+p);
                    Thread.sleep(100);

                    Log.d("","Received :) ");
                    } catch(Exception e)
                    {
                        e.printStackTrace();
                    }


        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        return null;
    }

.....................这是在异步背景进程中接收 UDP 数据包的代码,但是我没有收到一个数据包......我的代码有什么问题?我怎样才能克服这个问题?

4

1 回答 1

0

看来接收,不需要在DatagramPacket中指定ip和port。

DatagramPacket p = new DatagramPacket(buffer, buffer.length);
于 2013-07-03T21:43:59.637 回答