莱芜网站优化,杭州购物网站建设,太原做响应式网站设计,为什么要网站备案目录
一、TCP客户端UI
1、UI展示
2、xml代码
二、TCP客户端数据发送
三、TCP客户端数据接收 一、TCP客户端UI
1、UI展示 2、xml代码
?xml version1.0 encodingutf-8?
RelativeLayout xmlns:androidhttp://schemas.android.…目录
一、TCP客户端UI
1、UI展示
2、xml代码
二、TCP客户端数据发送
三、TCP客户端数据接收 一、TCP客户端UI
1、UI展示 2、xml代码
?xml version1.0 encodingutf-8?
RelativeLayout xmlns:androidhttp://schemas.android.com/apk/res/androidxmlns:apphttp://schemas.android.com/apk/res-autoxmlns:toolshttp://schemas.android.com/toolsandroid:layout_widthmatch_parentandroid:layout_heightmatch_parentandroid:background#59b1eftools:context.MainActivity4Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:idid/btn_client_sendandroid:text发送android:textSize25spandroid:layout_marginTop20dpandroid:layout_centerHorizontaltrueandroid:onClickbtn_client_send_clicked /TextViewandroid:idid/text_viewandroid:layout_widthmatch_parentandroid:textSize30spandroid:layout_height300dpandroid:layout_belowid/btn_client_sendandroid:layout_marginTop20dpandroid:layout_marginLeft20dpandroid:layout_marginRight20dpandroid:background#ffffff /Buttonandroid:layout_widthwrap_contentandroid:layout_heightwrap_contentandroid:idid/btn_startandroid:text开始android:layout_belowid/text_viewandroid:textSize25spandroid:layout_marginTop20dpandroid:layout_centerHorizontaltrueandroid:onClickbtn_start_clicked /TextViewandroid:idid/text_view2android:layout_widthmatch_parentandroid:textSize30spandroid:text0android:layout_height100dpandroid:layout_belowid/btn_startandroid:layout_marginTop20dpandroid:layout_marginLeft20dpandroid:layout_marginRight20dpandroid:background#ffffff //RelativeLayout
二、TCP客户端数据发送
public void Client_SendMessage(){try {Socket client new Socket(192.168.124.6,8089);OutputStream out client.getOutputStream();out.write(meng.getBytes());} catch (IOException e) {throw new RuntimeException(e);}}public void btn_client_send_clicked(View v){new Thread(new Runnable() {Overridepublic void run() {Client_SendMessage();}}).start();}
三、TCP客户端数据接收
textView1 findViewById(R.id.text_view);
textView1.setText(数据接收框);
textView2 findViewById(R.id.text_view2);
textView2.setText(0);
new Thread(new Runnable() {Overridepublic void run() {while (true){try {Socket client new Socket(192.168.124.6,8089);int len;InputStream in client.getInputStream();byte[] data new byte[128];len in.read(data);String str new String(data,0,len);Message msg2 new Message();Bundle b new Bundle();b.putString(msg, str);msg2.setData(b);h2.sendMessage(msg2);} catch (IOException e) {throw new RuntimeException(e);}}}}).start();
h2 new Handler(){Overridepublic void handleMessage(Message msg2) {// TODO Auto-generated method stubsuper.handleMessage(msg2);Bundle b msg2.getData();String string b.getString(msg);textView1.setText(string);}};