编程论坛's Archiver

sophie0308 发表于 2008-3-13 16:04

求助:手机使用socket连接接收数据慢

用j2me写了一个电子白板,终端同时使用模拟器和手机。手机上绘图时在模拟器上显示很快,但是在模拟器上绘图时手机上显示很慢。
不知道什么原因,指点一下吧!

wenshu 发表于 2008-3-14 09:42

应该再说的详细一些,比如是如何传递图像的,可以贴一点代码出来。。。

千里冰封 发表于 2008-3-14 18:41

手机的速度当然没有电脑快了
还有,传输的数据也没有那么实时啊

sophie0308 发表于 2008-3-19 15:24

部分代码如下

connectServer()用来连接服务器
public void drawReceive()用来接收数据
        public void connectServer(){
                try{
        SocketConnection connection = (SocketConnection)Connector.open("socket://59.64.158.197:"+SERVER_PORT);
                        connection.setSocketOption(SocketConnection.KEEPALIVE, 5);
                        connection.setSocketOption(SocketConnection.DELAY, 0);
                        connection.setSocketOption(SocketConnection.LINGER, 0);
                        io_in = connection.openDataInputStream();
                        io_out = connection.openDataOutputStream();

                }catch(IOException ioe){
                        ioe.printStackTrace();
                }
                myClass.connected = true;
        }
        public void drawReceive(){
                while(myClass.connected){
                        try{
                                DataBag dataBag = new DataBag(0,0,0,0,0,true,0);
                                dataBag.color = io_in.readInt();
                                dataBag.sX = io_in.readInt();
                                dataBag.sY = io_in.readInt();
                                dataBag.eX = io_in.readInt();
                                dataBag.eY = io_in.readInt();
                                dataBag.commandCenter = io_in.readInt();
                                dataBag.received = true;
                                myClass.commandCenter(dataBag,dataBag.commandCenter);
                        }catch(IOException ioe){
                                ioe.printStackTrace();
                                myClass.exit();
                        }
                }
        }

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.