首页 > 学院 > 开发设计 > 正文

CMNET和CMWAP网络连接

2019-11-17 06:06:57
字体:
来源:转载
供稿:网友

       J2me上的GPRS网络接入点有两个,一个就是CMNET,一个就是CMWAP。一般移动梦网,百宝箱就是挂在CMWAP上的。

 

CMNET

CMNET就是一般的互联网的网络接入点。我们一般在SUN那里看到的J2ME实例代码都是基于CMNET接入点的网络下载。一般来说,CMNET可以连接所有的网络站点。下面就是我在开发仙剑的CMNET的下载资源包的代码片断。

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

   * 下载网络文件

   * @param url String 要下载的文件的地址URL

   * @return byte[] 假如下载成功,返回文件的字节缓冲;

   *             假如下载失败,返回null

   */

  public byte[] download_CMNET(String url) {

    ContentConnection c;

    InputStream is = null;

    byte[] data = null;

    try {

       c= (ContentConnection)Connector.open("http://"+ServerName+"/"+url,Connector.READ,true);

       is = c.openInputStream();

       int dataLength = (int) c.getLength();

       if (dataLength == -1) {

         ByteArrayOutputStream bStrm = new ByteArrayOutputStream();

         int ch;

         while ( (ch = is.read()) != -1)

           bStrm.write(ch);

         data = bStrm.toByteArray();

         bStrm.close();



发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表