安卓客户端电脑服务器 udp 手机到连接那步就不运行了

eclipse juno 电脑是jre1.8 手机是安卓4.1.2
服务器到接受信息卡住,手机到连接服务器卡住
没报错
我试了手机连电脑开的wifi和手机电脑连一个wifi都不行
不知是哪出了问题?
刚注册的没悬赏见谅

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

    button1=(Button)findViewById(R.id.button1);
    editText1=(EditText)findViewById(R.id.editText1);
    editText2=(EditText)findViewById(R.id.editText2);       
/* // 开启服务器
        ExecutorService exec = Executors.newCachedThreadPool();
        UDPServer server = new UDPServer();
        exec.execute(server);*/
   // int port = 5050;
    new AlertDialog.Builder(MainActivity.this).setTitle("测试").setMessage("创建成功").setPositiveButton("确定", null).show();
    try
    {
        addr = InetAddress.getByName("192.168.191.4");
        new AlertDialog.Builder(MainActivity.this).setTitle("测试").setMessage("ip").setPositiveButton("确定", null).show();
   //   dClient = new DatagramSocket(PORT,addr);
        dClient = new DatagramSocket();   //随机端口
        new AlertDialog.Builder(MainActivity.this).setTitle("测试").setMessage("连接  UDP 成功").setPositiveButton("确定", null).show();
        button1.setOnClickListener(new OnClickListener() 
            { 
            public void onClick(View v) 
            { 

                String str1 = editText1.getText().toString();
                String str2 = editText2.getText().toString();
                Pattern p = Pattern.compile("[^( |\\n)*]");         //匹配  除了空白以外的字符
                Matcher m = p.matcher(str2);
                if(m.find()==true)     //不能只含有空格或者回车
                {                   
                    /*String msg;
                    try
                    {
                        Socket socket = new Socket("202.204.48.135",5554);
                        PrintWriter out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);      
                        out.println(str2);
                        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); 
                        msg = br.readLine();*/
                    str2="ID1:\n"+str2;
                //  str1="frag";
                //  editText1.setText(str1);
                    DatagramPacket sendPacket = new DatagramPacket(str2.getBytes() ,str2.length() , addr , PORT);
                    try
                    {
                        dClient.send(sendPacket);
                    } catch (IOException e)
                    {
                        // TODO 自动生成的 catch 块
                        e.printStackTrace();
                    }
                    //  str1=str1+"\n"+"ID1:\n"+str2+"\n";
                    //  editText1.setText(str1);
                        editText2.setText(null);
                /*   } catch (IOException e)
                    {
                        // TODO 自动生成的 catch 块
                        e.printStackTrace();
                    }   */  
                }
                else 
                {
                    editText2.setText(null);
                }

            } 
            }); 
    } catch (UnknownHostException e)
    {
        // TODO 自动生成的 catch 块
        e.printStackTrace();
    } catch (SocketException e)
    {
        // TODO 自动生成的 catch 块
        e.printStackTrace();
    }


}


//以下是自动生成的
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}


上面第3个对话框不弹 估计就是datagramSocket出问题了但是没看出来哪错了 因为看网上基本都是这么写的

http://www.cnblogs.com/kissazi2/p/3157755.html

安卓的联网,比如这里你udp创建,他其实很耗时间,直接写是不行的,简单讲就是界面线程不能耗时,你要是要完整可以运行的工程可以联系我

不能在主线程中联网。。。。要新建线程

android在4.0版本之后就不能在主线程中去更新UI了,那样会包异常,是为了防止网络请求时间过长,造成更新界面的卡顿,影响用户的体验。
有三种解决方案:
一、就是开辟一个子线程,把你联网的操作拿到线程中去执行。
二、使用android的Handler Message机制
三、使用异步任务(AsyncTask)的方式去执行网络的调用。

这个是我之前的一个课程设计 题目任意 就想到做的这个 不过后来因为时间紧急 临时改了题目 感谢上面各位回答