tambc

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            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? = ? " 服務(wù)器當(dāng)前時(shí)間: " ? + ?str? + ? " <BR> " ;?
          ?8 ???? byte []?pdu? = ?str.getBytes();?
          ?9 ????os.write(pdu);?
          10 ????os.flush();?
          11 ????System.out.println(Thread.currentThread().getName()? + ? " ??發(fā)送? " ? + ?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) 評(píng)論(1)  編輯  收藏 所屬分類: Java

          Feedback

          # re: 實(shí)現(xiàn)HTTP長(zhǎng)連接(服務(wù)器推) 2008-06-18 12:00 張偉
          yao lianjie
            回復(fù)  更多評(píng)論
            

          主站蜘蛛池模板: 韩城市| 鲁甸县| 财经| 龙门县| 伊通| 竹溪县| 福清市| 双城市| 清河县| 通许县| 和平区| 余江县| 轮台县| 巴楚县| 会泽县| 弥渡县| 梁平县| 昭通市| 贵溪市| 安新县| 阿克苏市| 贡嘎县| 万载县| 黔东| 余干县| 台中市| 汉寿县| 漳州市| 麻江县| 淳安县| 民勤县| 睢宁县| 祥云县| 吴桥县| 丹阳市| 远安县| 东阿县| 布拖县| 安宁市| 嘉义县| 曲周县|