无法在Android服务器上接收UDP数据包

时间:2013-02-09 11:04:55

标签: android udp

无法在Android手机上接收UDP数据包 在Android手机4.04 ICS上测试

public class Thread2 extends Activity implements Runnable 
{

public void run()
 {

        try { 
            InetAddress serverAddr = InetAddress.getByName("10.0.4.254"); 
            DatagramSocket socket = new DatagramSocket(11111, serverAddr); 
            byte[] buf = new byte[1024]; 
            DatagramPacket packet = new DatagramPacket(buf, buf.length);
            socket.receive(packet); 
            EditText et = (EditText) findViewById(R.id.editText1);
            et.setText(packet.getData().toString());
            } 
            catch (Exception e) { 
            Log.e("UDP", "***UDP Server creation Failed!"); 
            }
    } 
}

0 个答案:

没有答案