中文字幕 另类精品,亚洲欧美一区二区蜜桃,日本在线精品视频免费,孩交精品乱子片免费

<sup id="3hn2b"></sup>

    1. <sub id="3hn2b"><ol id="3hn2b"></ol></sub><legend id="3hn2b"></legend>

      1. <xmp id="3hn2b"></xmp>

      2. 新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > 開發(fā)MIDP聯(lián)網(wǎng)應(yīng)用程序

        開發(fā)MIDP聯(lián)網(wǎng)應(yīng)用程序

        作者: 時間:2012-05-07 來源:網(wǎng)絡(luò) 收藏

        *從控制臺輸出response

        */

        publicclassPOSTTestextendsMIDlet{

        /**

        *利用POST送信息

        */

        protectedvoidstartApp()throwsMIDletStateChangeException{

        try{

        HttpConnectioncon=(HttpConnection)Connector.open(http://localhost:8080/nec_server/servlet/ReverseServlet);

        //指定POST

        con.setRequestMethod(HttpConnection.POST);

        //在request中輸入數(shù)據(jù)

        Stringmessage=message=helloworld;

        DataOutputStreamdos=con.openDataOutputStream();

        byte[]messageByte=message.getBytes();

        for(inti=0;i

        dos.writeByte(messageByte[i]);

        }

        dos.flush();

        dos.close();

        //接收response

        DataInputStreamin=con.openDataInputStream();

        intinput;

        while((input=in.read())!=-1){

        System.out.print((char)input);

        }

        in.close();

        //關(guān)閉鏈接

        con.close();

        }catch(IOExceptione){

        e.printStackTrace();

        }

        }

        protectedvoidpauseApp(){

        }

        protectedvoiddestroyApp(booleanarg0)throwsMIDletStateChangeException{

        }

        }

        ex.8

        接下來介紹本次使用的SERVLETsample,作為服務(wù)器實際安裝的例子。因為本講座是講座,所以關(guān)于SERVLET的詳細(xì)說明就不再贅述,網(wǎng)上有許多這方面的信息,請大家參考Sun—http://java.sun.com/products/servlet/等網(wǎng)站。

        importjava.io.IOException;

        importjava.io.PrintWriter;

        importjavax.servlet.ServletException;

        importjavax.servlet.http.HttpServlet;

        importjavax.servlet.http.HttpServletRequest;

        importjavax.servlet.http.HttpServletResponse;

        /**

        *把接收的文字列進(jìn)行轉(zhuǎn)發(fā)的SERVLET

        */

        publicclassReverseServletextendsHttpServlet{

        /**

        *處理postrequest

        */

        protectedvoiddoPost(HttpServletRequestreq,HttpServletResponseres)

        throwsServletException,IOException{

        //接收參數(shù)

        Stringmessage=req.getParameter(message);

        //轉(zhuǎn)發(fā)文字

        Stringreverse=;

        for(inti=message.length();i>0;i--){

        reverse=reverse+message.charAt(i-1);

        }

        //寫response

        PrintWriterout=res.getWriter();

        out.write(

        n);

        out.write(

        n);

        out.write(

        n);

        out.write(n);

        out.write(

        n);

        out.write(messageis+message+
        n);

        out.write(ReverseMessageis+reverse+n);

        out.write(

        n);

        out.write();

        out.close();

        }

        }

        ex.9

        實際操作如下所示:

        2

        2.制作

        現(xiàn)在,我們介紹如何實際制作利用HTTP通信的。這次增添了以前所作的泡泡龍游戲(BlockApplication)的內(nèi)容,并把游戲結(jié)束的時間作成高低分一覽表,由服務(wù)器管理。為了使程序更簡單,還省略了與聲音相關(guān)的操作。以下是內(nèi)容改變前的sourcecode:

        BlockApplication.java

        BlockCanvas.java

        給這個程序添加

        •計算結(jié)束時間功能。

        •向服務(wù)器發(fā)送時間表功能。

        •從服務(wù)器接收最高分功能。

        通過游戲或游戲結(jié)束時,顯示出最高分。

        為了計算Http通信和時間表,給實際變量添加以下變量:

        //相關(guān)經(jīng)過時間

        privateintsecond=0;

        privatelongstartMs;

        //http通信類

        privatefinalStringSERVER_URL=

        http://localhost:8080/nec_server/servlet/BlockScoreServlet;//服務(wù)器的UPL

        privateString[]highscore=null;//最高分

        ex.10

        2.1.計算結(jié)束時間

        為了計算結(jié)束時間,要記錄游戲開始時的系統(tǒng)時間(startMs),以這個時間為準(zhǔn)計算經(jīng)過時間,如下畫面所示:

        /*****************************************

        *計時器相關(guān)處理

        *****************************************/

        /**

        *計算經(jīng)過時間

        */

        publicintgetSecond(){

        return(int)((System.currentTimeMillis()-startMs)/1000);

        }

        ex.11

        2.2.向服務(wù)器發(fā)送時間表,接收最高分

        如上所述,游戲結(jié)束時顯示最高分。但是,游戲結(jié)束時向服務(wù)器發(fā)送時間表,而通過游戲時不發(fā)送時間表,只顯示最高分。



        評論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉