日期:2014-05-16  浏览次数:21119 次

Apache MINA 蹇€熷叆闂ㄦ寚鍗?

from: http://tianting-wx.iteye.com/blog/265539聽聽

聽 鈥淢INA鏄竴涓猄ocket鐨勭綉缁滄鏋讹紝浣嗘槸瀹冩彁渚涗簡鏂逛究鐨凱rotocol鏀寔锛岄€氳繃瀹冪殑Encoder鍜孌ecoder锛屼綘灏嗕綘鐨勫簲鐢ㄥ彲浠ユ柟渚跨殑鎵╁睍骞舵敮鎸佸悇绉嶅熀浜嶴ocket鐨勭綉缁滃崗璁紝姣斿HTTP鏈嶅姟鍣ㄣ€丗TP鏈嶅姟鍣紙褰撶劧锛岃繖寰堝鏉傦級銆乀elnet鏈嶅姟鍣ㄧ瓑绛夈€傚熀浜嶮INA鐢ㄦ埛鍙互瀹规槗鍦板紑鍙戦珮鎬ц兘鍜岄珮浼哥缉鎬х殑缃戠粶搴旂敤绋嬪簭銆傗€?/p>

涓嬮潰鏄瀹樻柟鍏ラ棬鏂囨。鐨勪腑鏂囪瘧鐗堬紝鐢变簬瀹屽叏鍙傜収瀹樻柟鏂囨。鍦ㄧ▼搴忓叿浣撹繍琛屾椂閬囧埌涓€浜沬mport涓嶈冻鐨勬儏鍐碉紝鍦ㄧず渚嬫簮鐮佺殑import鏄垜鍦ㄤ翰鑷疄璺靛悗淇敼杩囩殑锛屽叾浠栫殑鍦版柟閮藉拰鍘熸枃涓€鏍枫€?/p>

Apache MINA 蹇€熷叆闂?/strong>

Added by Mark Webb, last edited by Trustin Lee on Apr 16, 2007聽聽聽 (view change)

1聽聽聽 绠€浠?/strong>

寤虹珛涓€涓熀浜嶮INA鐨勬椂闂存湇鍔″櫒锛屼笅闈㈢殑鍐呭闇€瑕佸厛鍑嗗濂姐€?/p>

1锛孧ina 1.1 Core
2锛孞DK 1.5 or greater
3锛孲LF4J 1.3.0 or greater 锛?br>聽 聽Log4J 1.2 users: slf4j-api.jar, slf4j-log4j12.jar, and Log4J 1.2.x
聽聽 Log4J 1.3 users: slf4j-api.jar, slf4j-log4j13.jar, and Log4J 1.3.x
聽聽 java.util.logging users: slf4j-api.jar and slf4j-jdk14.jar


聽聽 娉ㄦ剰锛氶鍏堣纭浣犱娇鐢ㄤ簡姝g‘鐨剆lf4j-*.jar 銆傛瘮濡傝slf4j-log4j12.jar 鍜宭og4j-1.3.x.jar 鏄笉鑳藉湪涓€璧蜂娇鐢ㄧ殑灏嗕細鍑虹幇鍔熻兘闅滅銆?/p>


聽锛堟垜鐢ㄤ簡1.2绯诲垪锛岄偅涔堟墍鏈夌殑杞欢鍖呭氨鏄細
聽log4j-1.2.14.jar锛?br>聽mina-core-1.1.2.jar锛?br>聽slf4j-api-1.2.jar锛?br>聽slf4j-jdk14-1.2.jar锛?br>聽slf4j-log4j12-1.2.jar锛?/p>

杩欎釜绋嬪簭鍙祴璇曚簡Windows2000pro 鍜?Linux绯荤粺锛屽苟涓斿湪鍋氱殑鏃跺€欐病鏈変緷璧栦簬涓€浜涘紑鍙戝钩鍙扮殑鐜銆?/p>

2聽聽聽 缂栧啓MINA鏃堕棿鏈嶅姟

涓嬮潰鍏堝缓绔嬩竴涓枃浠禡inaTimeServer.java锛屼唬鐮佸涓嬶細

Java浠g爜 澶嶅埗浠g爜
  1. publicclass聽MinaTimeServer聽{聽聽
  2. 聽聽聽聽publicstaticvoid聽main(String[]聽args)聽{聽聽
  3. 聽聽聽聽聽聽//聽code聽will聽go聽here聽next聽聽
  4. 聽聽聽聽}聽聽
  5. }聽聽
public class MinaTimeServer {
    public static void main(String[] args) {
      // code will go here next
    }
}

涓嬮潰浼氭參鎱㈠皢杩欎釜绫诲啓瀹岋紝杩欓噷鍏?/span>瀹氫箟涓€涓猰ain鐢ㄤ簬鍚姩绋嬪簭銆傝繖涓€姝ョ粨鏉熷悗锛?span style="color: #3366ff;">杩橀渶瑕佷竴涓洃鍚繛鎺ョ殑瀵硅薄锛屽洜涓鸿繖涓▼搴忔槸鍩轰簬TCP/IP鐨勶紝杩欓噷灏嗗鍔犱竴涓猄ocketAcceptor銆?/p>

聽聽

Java浠g爜 澶嶅埗浠g爜
  1. import聽org.apache.mina.common.IoAcceptor;聽聽
  2. import聽org.apache.mina.transport.socket.nio.SocketAcceptor;聽聽
  3. 聽聽
  4. publicclass聽MinaTimeServer聽{聽聽
  5. 聽聽聽聽public
友情链接: 爱易网 云虚拟主机技术 云服务器技术 程序设计技术 开发网站 APP开发教程
Copyright © 2013-2024 爱易网页 当前在线:238人  网站在2时6分19秒内访问总人数:22233人 当前 6.86%  粤ICP备18100884号-2