物联网网关通讯程序

上传人:kms****20 文档编号:40532255 上传时间:2018-05-26 格式:DOC 页数:5 大小:42KB
返回 下载 相关 举报
物联网网关通讯程序_第1页
第1页 / 共5页
物联网网关通讯程序_第2页
第2页 / 共5页
物联网网关通讯程序_第3页
第3页 / 共5页
物联网网关通讯程序_第4页
第4页 / 共5页
物联网网关通讯程序_第5页
第5页 / 共5页
亲,该文档总共5页,全部预览完了,如果喜欢就下载吧!
资源描述

《物联网网关通讯程序》由会员分享,可在线阅读,更多相关《物联网网关通讯程序(5页珍藏版)》请在金锄头文库上搜索。

1、package com.example.mysocket;import java.io.IOException; import java.io.OutputStream; import .Socket; import .UnknownHostException;import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widge

2、t.Button;public class MySocket extends Activity private Button button = null; private Button button1 = null; private Button button2 = null; private Button button3 = null; private Thread thread; private boolean go = true; int state = 0; int i; Override protected void onCreate(Bundle savedInstanceStat

3、e) super.onCreate(savedInstanceState); setContentView(R.layout.my_socket); button = (Button)findViewById(R.id.button); button.setOnClickListener(new EnterListener(); button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(new Enter1Listener(); button2 = (Button)findViewById(R.id.but

4、ton2); button2.setOnClickListener(new Enter2Listener(); button3 = (Button)findViewById(R.id.button3); button3.setOnClickListener(new Enter3Listener(); thread = new Thread(new SendRunnable(); thread.start(); class EnterListener implements OnClickListener public void onClick(View v) state = 1; class E

5、nter1Listener implements OnClickListener public void onClick(View v) state = 2; class Enter2Listener implements OnClickListener public void onClick(View v) state = 3; class Enter3Listener implements OnClickListener public void onClick(View v) state = 4; class SendRunnable implements RunnableOutputSt

6、ream os = null; int arg; Override public void run() / TODO Auto-generated method stub while(go) switch(state) case 1: try Socket s = new Socket(“192.168.16.254“, 8080); os = s.getOutputStream(); os.write(0); os.flush(); os.close(); s.close(); catch (UnknownHostException e) / TODO Auto-generated catc

7、h block e.printStackTrace(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); state = 0; break; case 2: try Socket s = new Socket(“192.168.16.254“, 8080); os = s.getOutputStream(); os.write(1); os.flush(); os.close(); s.close(); catch (UnknownHostException e) / TODO Auto-

8、generated catch block e.printStackTrace(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); state = 0; break; case 3: try Socket s = new Socket(“192.168.16.254“, 8080); os = s.getOutputStream(); os.write(2); os.flush(); os.close(); s.close(); catch (UnknownHostException e

9、) / TODO Auto-generated catch block e.printStackTrace(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); state = 0; break; case 4: try Socket s = new Socket(“192.168.16.254“, 8080); os = s.getOutputStream(); os.write(3); os.flush(); os.close(); s.close(); catch (UnknownHostException e) / TODO Auto-generated catch block e.printStackTrace(); catch (IOException e) / TODO Auto-generated catch block e.printStackTrace(); state = 0; break;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号