最代码官方
2014-11-27 14:59:36
证精
apache Mina开发实现多人聊天室程序命令行版本
最近开发最代码的一些小项目模块:搜索和邮件,由于服务器资源只有2g内存,而且感觉就一个http接口提供启动一个tomcat服务确实有些重,于是调研过程中了解到了apache的mina项目,基本满足了目前的需求,轻量级,快速部署。
根据csdn的博客总结分享一个由mina实现的多人聊天室程序吧,不过是命令行版本的,但对于入门mina开发来说足够了。
项目截图:
运行截图:
启动com.zuidaima.mina.server.MinaServer.java和多个com.zuidaima.mina.client.RunClient.java实例后
Server客户端接收信息:
2014-11-27 14:41:18,353 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 创建一个新连接:/192.168.5.76:53903 --- 2014-11-27 14:41:18,357 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetEncoder] --- #############字符编码############ --- 2014-11-27 14:41:18,362 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 打开一个session:1#0 --- 2014-11-27 14:41:18,365 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 服务器发送消息: welcome to the chat room ! --- 2014-11-27 14:41:18,368 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetDecoder] --- #########decode######### --- 2014-11-27 14:41:18,368 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 服务器接收到数据: 连接服务器成功! --- 2014-11-27 14:41:18,380 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 转发 messageReceived: 2014-11-27 02:41:18 连接服务器成功! --- 2014-11-27 14:41:18,380 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetEncoder] --- #############字符编码############ --- 2014-11-27 14:41:18,381 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 服务器发送消息: 2014-11-27 02:41:18 连接服务器成功! --- 2014-11-27 14:41:21,636 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 创建一个新连接:/192.168.5.76:53926 --- 2014-11-27 14:41:21,636 [NioProcessor-3] INFO [com.zuidaima.mina.server.code.CharsetEncoder] --- #############字符编码############ --- 2014-11-27 14:41:21,637 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 打开一个session:2#0 --- 2014-11-27 14:41:21,637 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 服务器发送消息: welcome to the chat room ! --- 2014-11-27 14:41:21,666 [NioProcessor-3] INFO [com.zuidaima.mina.server.code.CharsetDecoder] --- #########decode######### --- 2014-11-27 14:41:21,666 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 服务器接收到数据: 连接服务器成功! --- 2014-11-27 14:41:21,667 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 转发 messageReceived: 2014-11-27 02:41:21 连接服务器成功! --- 2014-11-27 14:41:21,667 [NioProcessor-3] INFO [com.zuidaima.mina.server.code.CharsetEncoder] --- #############字符编码############ --- 2014-11-27 14:41:21,667 [NioProcessor-3] INFO [com.zuidaima.mina.server.code.CharsetEncoder] --- #############字符编码############ --- 2014-11-27 14:41:21,667 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 服务器发送消息: 2014-11-27 02:41:21 连接服务器成功! --- 2014-11-27 14:41:21,667 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 服务器发送消息: 2014-11-27 02:41:21 连接服务器成功! --- 2014-11-27 14:41:51,965 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 当前连接/192.168.5.76:53903处于空闲状态:both idle --- 2014-11-27 14:41:51,965 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 当前连接/192.168.5.76:53926处于空闲状态:both idle --- 2014-11-27 14:42:22,211 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 当前连接/192.168.5.76:53926处于空闲状态:both idle --- 2014-11-27 14:42:22,213 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 当前连接/192.168.5.76:53903处于空闲状态:both idle --- 2014-11-27 14:42:52,376 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 当前连接/192.168.5.76:53903处于空闲状态:both idle --- 2014-11-27 14:42:52,381 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 当前连接/192.168.5.76:53926处于空闲状态:both idle --- 2014-11-27 14:43:22,532 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 当前连接/192.168.5.76:53903处于空闲状态:both idle --- 2014-11-27 14:43:22,538 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 当前连接/192.168.5.76:53926处于空闲状态:both idle --- 2014-11-27 14:43:51,847 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetDecoder] --- #########decode######### --- 2014-11-27 14:43:51,847 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 服务器接收到数据: 张三我来了 --- 2014-11-27 14:43:51,848 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 转发 messageReceived: 2014-11-27 02:43:51 张三我来了 --- 2014-11-27 14:43:51,848 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetEncoder] --- #############字符编码############ --- 2014-11-27 14:43:51,848 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetEncoder] --- #############字符编码############ --- 2014-11-27 14:43:51,851 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 服务器发送消息: 2014-11-27 02:43:51 张三我来了 --- 2014-11-27 14:43:51,849 [NioProcessor-3] INFO [com.zuidaima.mina.server.message.ServerMessageHandler] --- 服务器发送消息: 2014-11-27 02:43:51 张三我来了 ---
张三客户端接收信息:
2014-11-27 14:41:18,358 [main] INFO [com.zuidaima.mina.server.code.CharsetEncoder] --- #############字符编码############ --- 2014-11-27 14:41:18,363 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ClientMessageHandlerAdapter] --- messageSent 客户端发送消息:连接服务器成功! --- 2014-11-27 14:41:18,367 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetDecoder] --- #########decode######### --- 2014-11-27 14:41:18,367 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ClientMessageHandlerAdapter] --- client receive a message is : welcome to the chat room ! --- 2014-11-27 14:41:18,381 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetDecoder] --- #########decode######### --- 2014-11-27 14:41:18,381 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ClientMessageHandlerAdapter] --- client receive a message is : 2014-11-27 02:41:18 连接服务器成功! --- 2014-11-27 14:41:21,668 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetDecoder] --- #########decode######### --- 2014-11-27 14:41:21,668 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ClientMessageHandlerAdapter] --- client receive a message is : 2014-11-27 02:41:21 连接服务器成功! --- 张三我来了 2014-11-27 14:43:51,845 [main] INFO [com.zuidaima.mina.server.code.CharsetEncoder] --- #############字符编码############ --- 2014-11-27 14:43:51,846 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ClientMessageHandlerAdapter] --- messageSent 客户端发送消息:张三我来了 --- 2014-11-27 14:43:51,852 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetDecoder] --- #########decode######### --- 2014-11-27 14:43:51,852 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ClientMessageHandlerAdapter] --- client receive a message is : 2014-11-27 02:43:51 张三我来了 ---
李四客户端接收信息:
2014-11-27 14:41:21,661 [main] INFO [com.zuidaima.mina.server.code.CharsetEncoder] --- #############字符编码############ --- 2014-11-27 14:41:21,661 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetDecoder] --- #########decode######### --- 2014-11-27 14:41:21,662 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ClientMessageHandlerAdapter] --- client receive a message is : welcome to the chat room ! --- 2014-11-27 14:41:21,666 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ClientMessageHandlerAdapter] --- messageSent 客户端发送消息:连接服务器成功! --- 2014-11-27 14:41:21,668 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetDecoder] --- #########decode######### --- 2014-11-27 14:41:21,668 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ClientMessageHandlerAdapter] --- client receive a message is : 2014-11-27 02:41:21 连接服务器成功! --- 2014-11-27 14:43:51,850 [NioProcessor-2] INFO [com.zuidaima.mina.server.code.CharsetDecoder] --- #########decode######### --- 2014-11-27 14:43:51,851 [NioProcessor-2] INFO [com.zuidaima.mina.server.message.ClientMessageHandlerAdapter] --- client receive a message is : 2014-11-27 02:43:51 张三我来了 ---
原文:http://blog.csdn.net/ibm_hoojo/article/details/7817303
猜你喜欢
- apache mina入门教程hello world简单实例源代码下载
- java swing聊天室程序--带语音
- java socket控制台版本聊天室程序源码下载
- java实现最简单的web聊天室程序源代码,适合初学者
- java socket开发最简易的聊天室源码分享
- java swing聊天室代码
- Netty5.0+HTML制作的网页聊天室
- JSP聊天室2.0版
- java swing编写简易聊天室,java初学者可以学习java线程与网络编程的基础知识
- java swing开发大猫聊天室源码,简单易懂,适合java swing初学者
- Java WebSocket开发聊天室实例
- jsp开发简单聊天室demo
请下载代码后再发表评论
文件名:apache Mina开发实现多人聊天室程序命令行版本.rar,文件大小:15.252K
下载
- /
- /zuidaima_mina_client
- /zuidaima_mina_client/.classpath
- /zuidaima_mina_server
- /zuidaima_mina_server/.classpath
- /zuidaima_mina_server/.project
- /zuidaima_mina_server/pom.xml
- /zuidaima_mina_server/src
- /zuidaima_mina_server/src/main
- /zuidaima_mina_server/src/main/java
- /zuidaima_mina_server/src/main/java/com
- /zuidaima_mina_server/src/main/java/com/zuidaima
- /zuidaima_mina_server/src/main/java/com/zuidaima/mina
- /zuidaima_mina_server/src/main/java/com/zuidaima/mina/server
/zuidaima_mina_server/src/main/java/com/zuidaima/mina/server/MinaServer.java
- /zuidaima_mina_server/src/main/java/com/zuidaima/mina/server/code
- /zuidaima_mina_server/src/main/java/com/zuidaima/mina/server/factory
- /zuidaima_mina_server/src/main/java/com/zuidaima/mina/server/message
- /zuidaima_mina_server/src/main/java/com/zuidaima/mina/server
- /zuidaima_mina_server/src/main/java/com/zuidaima/mina
- /zuidaima_mina_server/src/main/java/com/zuidaima
- /zuidaima_mina_server/src/main/java/com
- /zuidaima_mina_server/src/main/resources
- /zuidaima_mina_server/src/main/resources/log4j.properties
- /zuidaima_mina_server/src/main/java
- /zuidaima_mina_server/src/main
- /zuidaima_mina_client
最近下载
crosa_Don LV18
2022年7月23日
LHJ123 LV30
2019年2月1日
wen332 LV6
2019年1月4日
253702090 LV3
2018年5月19日
jic499 LV27
2018年4月14日
1943815081 LV13
2018年4月13日
lyh1989 LV34
2017年12月7日
fangjishuai LV2
2017年11月30日
dagf113225 LV68
2017年8月30日
xjc621105 LV17
2017年4月25日
最近浏览
hxy19991216 LV4
2023年12月20日
fuyouou LV5
2023年6月29日
crosa_Don LV18
2022年7月23日
Sopuding LV1
2022年7月16日
eddie2260 LV2
2022年6月17日
yuxinnan LV4
2022年3月19日
494785 LV5
2021年12月15日
守望 LV2
2021年7月14日
1005948011 LV7
2021年6月1日
xiongfan LV6
2021年1月29日