tambc

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            5 Posts :: 21 Stories :: 5 Comments :: 0 Trackbacks
          ?1 response.setContentType( " text/html " );?
          ?2 ??ServletOutputStream?os? = ?response.getOutputStream();?
          ?3 ??SimpleDateFormat?format? = ? new ?SimpleDateFormat( " yyyy-MM-dd?HH:mm:ss " );?
          ?4 ?? while ?( true )? {?
          ?5 ??? try ? {?
          ?6 ????String?str? = ?format.format( new ?java.util.Date());?
          ?7 ????str? = ? " 服務器當前時間: " ? + ?str? + ? " <BR> " ;?
          ?8 ???? byte []?pdu? = ?str.getBytes();?
          ?9 ????os.write(pdu);?
          10 ????os.flush();?
          11 ????System.out.println(Thread.currentThread().getName()? + ? " ??發送? " ? + ?str);?
          12 ???? try ? {?
          13 ?????Thread.sleep( 3000 );?
          14 ????}
          ? catch ?(InterruptedException?ex)? {?
          15 ????}
          ?
          16 ???}
          ? catch ?(IOException?e)? {?
          17 ????System.out.println(?
          18 ?????Thread.currentThread().getName()? + ? " ??客戶端斷開連接 " );?
          19 ???? break ;?
          20 ???}
          ?
          21 ??}
          posted on 2006-12-21 11:40 tambc 閱讀(1162) 評論(1)  編輯  收藏 所屬分類: Java

          Feedback

          # re: 實現HTTP長連接(服務器推) 2008-06-18 12:00 張偉
          yao lianjie
            回復  更多評論
            

          主站蜘蛛池模板: 秦安县| 南投县| 南宫市| 安康市| 阿拉善右旗| 济南市| 景谷| 景东| 东山县| 枝江市| 博湖县| 甘南县| 张家港市| 泸溪县| 固原市| 丰台区| 轮台县| 大名县| 会昌县| 虞城县| 海安县| 新绛县| 马公市| 托里县| 梓潼县| 临海市| 遂川县| 武宁县| 金昌市| 洛隆县| 上栗县| 阿坝县| 巴彦淖尔市| 紫阳县| 余庆县| 武乡县| 吴江市| 丹江口市| 林西县| 霞浦县| 石渠县|