J2ME 中的无线通信协议
来源:互联网 发布:仙知机器人 编辑:程序博客网 时间:2024/06/10 07:37
- package HttpConnection;
- import java.io.DataInputStream;
- import java.io.IOException;
- import javax.microedition.io.ConnectionNotFoundException;
- import javax.microedition.io.Connector;
- import javax.microedition.io.HttpConnection;
- /**********************************************************************
- *
- * @author
- *Description:发送请求消息,返回字符串数据
- ***********************************************************************/
- public class HttpStringThread implements Runnable{
- String host;
- String parameter;
- HttpConnection hc;
- DataInputStream dis;
- public String result;
- String canvas;
- String resURL;
- TaskInterface ti;
- public HttpStringThread(String resURL,TaskInterface ti){
- this.resURL = resURL;
- this.canvas=null;
- if(resURL.indexOf("/") == -1){
- host = resURL;
- parameter = "";
- }else{
- host = resURL.substring(0,resURL.indexOf("/"));
- parameter = resURL.substring(resURL.indexOf("/"));
- }
- this.ti=ti;
- }
- public HttpStringThread(String resURL){
- ti=null;
- this.resURL = resURL;
- this.canvas=null;
- if(resURL.indexOf("/") == -1){
- host = resURL;
- parameter = "";
- }else{
- host = resURL.substring(0,resURL.indexOf("/"));
- parameter = resURL.substring(resURL.indexOf("/"));
- }
- }
- public HttpStringThread(String resURL,TaskInterface ti,String canvas){
- this.resURL = resURL;
- this.canvas=canvas;
- if(resURL.indexOf("/") == -1){
- host = resURL;
- parameter = "";
- }else{
- host = resURL.substring(0,resURL.indexOf("/"));
- parameter = resURL.substring(resURL.indexOf("/"));
- }
- this.ti=ti;
- }
- public void run() {
- // TODO 自动生成方法存根
- try {
- /*
- hc = (HttpConnection)Connector.open("http://" + "10.0.0.172:80" //注,这里重点,代表某种机子通信需要代理
- + parameter,3,true); //服务地址,才能实现无线通信,
- hc.setRequestProperty("X-Online-Host",host);
- hc.setRequestProperty("Connection","close");
- */
- hc = (HttpConnection)Connector.open("http://"+resURL); //这种通信代表某和机子已经包含有代理服务地址
- hc.setRequestMethod(HttpConnection.GET); //设置
- dis = hc.openDataInputStream();
- int k;
- byte[] data = new byte[10240];
- int i = 0;
- while((k = dis.read()) != -1){
- data[i] = (byte)k;
- i++;
- }
- String s = new String(data,0,i);
- result=s;
- System.out.println("This is HttpStringThread");
- }catch(NullPointerException e){
- result="CommunicationError";
- }catch(ConnectionNotFoundException e){
- result="CommunicationError";
- }catch(IOException e){
- result="CommunicationError";
- }catch(Exception e){
- result="CommunicationError";
- }finally{
- System.out.println(result);
- try {
- hc.close();
- if(dis!=null){
- dis.close();
- }
- } catch (IOException e) {
- // TODO 自动生成 catch 块
- e.printStackTrace();
- }
- if(this.canvas!=null){
- ti.data(result, this.canvas);
- }else{
- ti.data(result);
- }
- }
- }
- }
- J2ME 中的无线通信协议
- 无线通信协议小感
- 无线通信协议有哪些
- android中的无线通信蓝牙
- 转贴(电脑报):J2ME无线通信编程入门
- 最近的任务--无线通信协议
- 无线通信中的小尺度衰落
- 无线通信
- 无线通信
- 无线通信
- 无线通信
- 无线通信协议设计的几点要素
- 智能硬件无线通信协议(二)
- 常用无线通信协议Zigbee、bluetooth、wifi比较
- 第一章 无线通信中的数字处理基础
- 无线通信原理及协议栈(ZigBee、蓝牙等)解析
- 无线通信原理及协议栈(ZigBee、蓝牙等)解析
- 智能硬件无线通信协议的那些事儿(一)
- S3c2410软件调试总结、启动代码分析大杂烩
- 财富在哪里?!
- sql server 2005 身份认证登录修改
- 什么是圈复杂度(Cyclomatic Complexity)
- WebService开发笔记 2 -- VS 2005 访问WebServcie更简单
- J2ME 中的无线通信协议
- 职场人士必须修炼的四大职业情商
- 越狱 第四季(1-3)
- ORACLE的常用操作
- ucGUI390 触摸消息响应过程
- GEF几何图形编辑器
- jdbc连接oracle全过程
- 作者: 石志国 清华大学出版社
- 摄像头互动游戏开发