手机蓝牙延时的问题

fxy1 2009-02-10 01:24:57
现在做了一个炸弹超人的蓝牙对站游戏。在测试机上均测试成功,但在手机上测试,发现手机服务端发送,手机客户端接受,这个没问题,一点延时也没有,但是手机客户端发送,手机服务器端接受会有延时出现,就是手机客户端已经走了N步,差不多有两三秒的样子吧!手机服务器端的人才开始快速走到位。一直都是这样。为什么?是程序有问题还是手机本身蓝牙配置有问题?
...全文
338 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
fxy1 2009-02-17
  • 打赏
  • 举报
回复
是的不混淆代码是好好的,一混淆就有延迟问题。郁闷
fxy1 2009-02-13
  • 打赏
  • 举报
回复
是将Java的Class代码,做混淆,让别人不能反编译的东东,就是看不到源码。
biaozai06 2009-02-13
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 fxy1 的回复:]
是将Java的Class代码,做混淆,让别人不能反编译的东东,就是看不到源码。
[/Quote]

第一次听说混淆器,呵呵,受教了

你的程序如果不用混淆器打包就不会出现延迟问题是吧?
fxy1 2009-02-12
  • 打赏
  • 举报
回复
谁能帮我想一下混淆器怎么弄,可以不出现这种问题!
biaozai06 2009-02-12
  • 打赏
  • 举报
回复
混淆器是什么东东。。?
fxy1 2009-02-11
  • 打赏
  • 举报
回复
代码太多了。上传那一段好呢。
fxy1 2009-02-11
  • 打赏
  • 举报
回复
晕死了。才发现原来不能混淆打包,一混淆打包就会出错,如果不混淆打包,程序都是好的。为什么。晕死了
fxy1 2009-02-11
  • 打赏
  • 举报
回复
package game;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.util.TimerTask;

import javax.bluetooth.BluetoothStateException;
import javax.bluetooth.LocalDevice;
import javax.bluetooth.ServiceRecord;
import javax.bluetooth.UUID;
import javax.microedition.io.Connector;
import javax.microedition.io.StreamConnection;
import javax.microedition.io.StreamConnectionNotifier;

public class BtoothTask extends TimerTask{


private static final UUID PICTURES_SERVER_UUID =
new UUID("F0E0D0C0B0A000908070605040302010", false);

/** The attribute id of the record item with images names. */
private static final int IMAGES_NAMES_ATTRIBUTE_ID = 0x4321;

/** Keeps the local device reference. */
private LocalDevice localDevice;

/** Accepts new connections. */
private StreamConnectionNotifier notifier;

/** Keeps the information about this server. */
private ServiceRecord record;


/** Becomes 'true' when this component is finalized. */
private boolean isClosed;


private String tf="this is server";



/** Process the particular client from queue. */


private StreamConnection conn=null;


//输出流
private DataOutputStream dos=null;


//输入流
private DataInputStream dis=null;

private Receive rc;

private GCanvas gcanvas;

private boolean iscon=true;



public BtoothTask(String mapstr,GCanvas gcanvas)
{


try {
localDevice=LocalDevice.getLocalDevice();
this.tf=mapstr;
rc=new Receive();

//new Thread(new Receive()).start();


this.gcanvas=gcanvas;
} catch (BluetoothStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}





}


public void run() {
// TODO Auto-generated method stub
while(conn==null&&iscon){


try{

notifier=(StreamConnectionNotifier)Connector.open("btspp://localhost:"+PICTURES_SERVER_UUID.toString()+
";name=CheckOne Server;authorize=false");



conn=notifier.acceptAndOpen();




dos=conn.openDataOutputStream();


dis=conn.openDataInputStream();

this.sendMessage(this.tf);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}


public void sendMessage(String msg){
try{



if(dos!=null)
{


dos.writeUTF(msg);

dos.flush();
}

}catch(Exception ex){
ex.printStackTrace();

try {
dos.close();
dis.close();
conn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

conn=null;
dos=null;
dis=null;

iscon=false;
}




}


private void ProcessMsg(String msg)
{

if(msg.indexOf("2#")!=-1)
{

int x=Integer.parseInt(msg.substring(msg.indexOf("#")+1,msg.indexOf("X")));

int y=Integer.parseInt(msg.substring(msg.indexOf("X")+1,msg.indexOf("Y")));

int p=Integer.parseInt(msg.substring(msg.indexOf("Y")+1,msg.indexOf("F")));

int b=Integer.parseInt(msg.substring(msg.indexOf("F")+1,msg.indexOf("B")));

this.gcanvas.setClientMan(x, y, p,b);

return;

}




}



class Receive implements Runnable{
private Thread processorThread;
public Receive()
{
processorThread = new Thread(this);
processorThread.start();
}


public void clearRR()
{
this.processorThread.interrupt();
}



private String recmsg="";


public void run(){
while(true){
try{

if(dis!=null)
{

recmsg=dis.readUTF()+"\n";




if(!recmsg.equals(""))
{

System.out.println(recmsg);
ProcessMsg(recmsg);
}



}
}catch(EOFException ex){

}
catch(Exception ex){
try {
dos.close();
dis.close();
conn.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

conn=null;
dos=null;
dis=null;

iscon=false;
}

/*

try
{
processorThread.sleep(1);
}
catch(Exception ex)
{

}
*/



}
}

}

public void ClearTh()
{
this.rc.clearRR();


}


}
biaozai06 2009-02-11
  • 打赏
  • 举报
回复
上传主设备接收蓝牙数据、主设备屏幕操作那段吧
jimnameboard 2009-02-10
  • 打赏
  • 举报
回复
能不能把代码上传来研究一下?
jimnameboard 2009-02-10
  • 打赏
  • 举报
回复
能不能把代码上传来研究一下?
nick207 2009-02-10
  • 打赏
  • 举报
回复
学习中
fxy1 2009-02-10
  • 打赏
  • 举报
回复
有没有好的测试调试方法?
fxy1 2009-02-10
  • 打赏
  • 举报
回复
但服务器端的接受代码,和客户端的接受代码是一样的啊!而且在模拟测试下是没有任何问题的。只是在手机情况下会出现这样的问题。为什么?难道服务器端是主动连接所以发送比较好?客户端是被动连接接受比较好?
biaozai06 2009-02-10
  • 打赏
  • 举报
回复
一般说来蓝牙通讯不会出现单方向的延时。

LZ说“手机服务器端的人才开始快速走到位”,感觉应该是程序问题。

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧