Android编程之客户端通过socket与服务器通信的方法

2019-12-10 19:51:35刘景俊
  •           if ( msg != null )             {  
  •             mTextView.setText(msg);             }  
  •           else            {  
  •             mTextView.setText("数据错误!");             }  
  •           //关闭流             out.close();  
  •           br.close();             //关闭Socket  
  •           socket.close();            }  
  •         catch (Exception e)            {  
  •           // TODO: handle exception             Log.e(DEBUG_TAG, e.toString());  
  •         }         }  
  •     });     }  
  • }  ?

    布局文件main.xml
     

    1. <?xml version="1.0" encoding="utf-8"?>   <LinearLayout xmlns:android="http://www.easck.com/apk/res/android" 
    2.   android:orientation="vertical"    android:layout_width="fill_parent" 
    3.   android:layout_height="fill_parent"    >  
    4.   <TextView    android:id="@+id/TextView01" 
    5.   android:layout_width="fill_parent"    android:layout_height="wrap_content"