手机定时发送数据 间断问题 困扰了1个月 手机threadService 定时发送 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 同类问题,共勉!原因不祥!我准备把Http的方法费了,用Socket直接做。不知道下面的代码行不行。 public void networksend(){ //将有用的上传数据打包至一个buf,Length是打后的长度。 StructPackandUnPack.structInt Length = new StructPackandUnPack.structInt(); byte[] buf = m_structphonesignal.PacketDatatoNewBuf(Length); if(buf!=null){ //try to send packet to PC. try { Socket sock = new Socket(Dst, 8080,Src,8080); OutputStream OPS= sock.getOutputStream(); OPS.write(buf); OPS.flush(); //waitfor output finished. Thread.sleep(1000); InputStream INS= sock.getInputStream(); INS.read(buf); Thread.sleep(1000); sock.shutdownOutput(); sock.shutdownInput(); sock.close(); } catch (UnknownHostException e){ e.printStackTrace(); }catch (IOException e){ e.printStackTrace(); }catch (Exception e){ e.printStackTrace(); } }else{ //something is wrong. } } 一秒一次,够浪费的,完全可以设定 10 分钟啊,注意 thread 中要进行电源管理避免休眠,另外就是手机端要有发送失败重发的机制,估计是网络信号问题。 Android中的声音获取进行频率分析 Dialog下的Builder单击事件如何能够跳转到一个新的Activity ?求教育 android不弹出“使用以下方式发送”的对话框 android Animation动画,如何让动画结束后没有影响。 android网络应用开发 eclipse中的一些界面控件没有了 安卓下面的webview配置问题 玩h5游戏失败 Eclipse Android XML编辑的问题 关于图片动画 FFmpegFrameRecorder录制视频不能设置视频帧率 求个cocos2d-x 写的单机斗地主游戏源码 如何布置这个布局?
StructPackandUnPack.structInt Length = new StructPackandUnPack.structInt();
byte[] buf = m_structphonesignal.PacketDatatoNewBuf(Length); if(buf!=null){
//try to send packet to PC.
try {
Socket sock = new Socket(Dst, 8080,Src,8080);
OutputStream OPS= sock.getOutputStream();
OPS.write(buf);
OPS.flush();
//waitfor output finished.
Thread.sleep(1000);
InputStream INS= sock.getInputStream();
INS.read(buf);
Thread.sleep(1000);
sock.shutdownOutput();
sock.shutdownInput();
sock.close();
}
catch (UnknownHostException e){
e.printStackTrace();
}catch (IOException e){
e.printStackTrace();
}catch (Exception e){
e.printStackTrace();
}
}else{
//something is wrong.
}
}