Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android上的UDP接收器_Android_Eclipse_Udp - Fatal编程技术网

android上的UDP接收器

android上的UDP接收器,android,eclipse,udp,Android,Eclipse,Udp,我想在eclipse上执行udp接收器。但它不起作用。udp发送器工作正常,数据包通过特定端口发送。但emulator无法通过udp发送方接收任何数据包。需要帮助 我不知道您的场景是什么,但根据我的场景,我只是在我的系统(Windows 7)上使用php脚本设置了一个UDP服务器,并使用以下代码成功地从android emulator发送和接收UDP数据包 String receivedString=""; byte[] sendData = new byte[1024];

我想在eclipse上执行udp接收器。但它不起作用。udp发送器工作正常,数据包通过特定端口发送。但emulator无法通过udp发送方接收任何数据包。需要帮助

我不知道您的场景是什么,但根据我的场景,我只是在我的系统(Windows 7)上使用php脚本设置了一个UDP服务器,并使用以下代码成功地从android emulator发送和接收UDP数据包

String receivedString="";

        byte[] sendData = new byte[1024];
        byte[] receiveData = new byte[1024];

        sendData = stringToBeSended.getBytes();

        DatagramPacket sendPacket = new DatagramPacket(sendData,
                sendData.length, IPAddress, port);

        DatagramSocket clientSocket;
        try {
            clientSocket = new DatagramSocket();


            clientSocket.send(sendPacket);

            DatagramPacket receivePacket = new DatagramPacket(receiveData,
                    receiveData.length);
            clientSocket.receive(receivePacket);
            receivedString = new String(receivePacket.getData());
            clientSocket.close();
        } catch (SocketException e) {
            Log.v("SocketExceptionOccured", e.toString())
            e.printStackTrace();
        } catch (IOException e) {
            Log.v("IOExceptionOccured", e.toString())
            e.printStackTrace();
        }

        Toast.makeText(getBaseContext(), receivedString, Toast.LENGTH_LONG).show();

您正在将哪个设备用于UDP服务器,哪个设备用于UDP客户端。。。。?在发送数据包之前,您是否正确启动了UDP服务器?请向我们展示代码,以便我们可以检查它。您好:)我正在使用labview软件发送数据包。并希望在emulator上接收。Neways,尝试上面的代码。希望它能起作用。待会儿告诉你,接收端没有进展。我在emulator或logcat上没有得到任何输出。我尝试了接收数据包的简单udp接收器代码,但没有成功。谁能帮我一下吗。