Java实现局域网聊天软件分享

          前言

                        翻翻u盘里面的东西,发现了自己以前实现的局域网聊天软件。这里共享出来给各位学习

                  Java的童鞋。对知识的渴望源自于人的内心,对知识的分享也源自于人的本性。

                   Java实现局域网聊天软件分享_第1张图片

         功能罗列

                      啥功能笔者就不去重新实践了,简单的罗列下功能列表:

                              1. 消息发送:用户可以发送消息给好友用户。
                              2. 消息接收:用户可以接收到好友用户发送给他的消息。
                              3、表情编辑:用户可以发送表情给好友,好友可以得到发送的表情
                              4、文件传输功能:好友之间可以实现文件的传输功能
                              5、好友之间可以实现远程协助
                              6、好友之间可以实现视频通信(待调试,貌似xp可以,其他不行)
                              7、用户可以编辑自己的状态、也可以给好友留言
                              8、支持离线消息的发送以及系统消息的获取
                              9、提供用户的查找、添加好友、删除好友
                             10、系统服务器管理功能:系统可以启动或者关闭服务。
                             11、系统提供一些必要的特色功能:音乐播放器、邮件发送(待实现)
                             12、消息历史记录

                      不过笔者貌似记得有些个功能还是不太完善的,希望有兴趣的童鞋可以自己发现并完善。

           项目结构

                          典型的C/S结构,自己实现了一个简单的服务器,主要实现客户端之间信息的转发,

                   离线消息的记录。看看工程结构:

                          服务器端:

                                     Java实现局域网聊天软件分享_第2张图片

                        客户端结构:

                                        Java实现局域网聊天软件分享_第3张图片

            如何运行 

                   1、SQL脚本导入

                            数据后台笔者使用的是MySQL数据库,因此想要运行的话,首先应该安装MySQL

                   数据库。这里我将其SQL脚本提供给读者,读者可自行导入创建数据库、表。

                            数据库名为ManChat

                      

/*
Navicat MySQL Data Transfer

Source Server         : localhost_3306
Source Server Version : 50051
Source Host           : localhost:3306
Source Database       : manchat

Target Server Type    : MYSQL
Target Server Version : 50051
File Encoding         : 65001

Date: 2013-05-28 22:35:49
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for `comment`
-- ----------------------------
DROP TABLE IF EXISTS `comment`;
CREATE TABLE `comment` (
  `auther` varchar(30) default NULL,
  `comment_content` varchar(50) default NULL,
  `commenter` varchar(30) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of comment
-- ----------------------------
INSERT INTO `comment` VALUES ('aaa', '来一下', 'bbb');
INSERT INTO `comment` VALUES ('bbb', '才回去', 'aaa');

-- ----------------------------
-- Table structure for `relationship`
-- ----------------------------
DROP TABLE IF EXISTS `relationship`;
CREATE TABLE `relationship` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `userid` int(10) unsigned NOT NULL,
  `friendid` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`id`),
  KEY `FK_relationship_1` (`userid`),
  KEY `FK_relationship_2` (`friendid`),
  CONSTRAINT `FK_relationship_1` FOREIGN KEY (`userid`) REFERENCES `userinfo` (`id`),
  CONSTRAINT `FK_relationship_2` FOREIGN KEY (`friendid`) REFERENCES `userinfo` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=77 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of relationship
-- ----------------------------
INSERT INTO `relationship` VALUES ('1', '1', '2');
INSERT INTO `relationship` VALUES ('2', '2', '1');
INSERT INTO `relationship` VALUES ('5', '1', '4');
INSERT INTO `relationship` VALUES ('6', '4', '1');
INSERT INTO `relationship` VALUES ('9', '1', '6');
INSERT INTO `relationship` VALUES ('10', '6', '1');
INSERT INTO `relationship` VALUES ('11', '2', '3');
INSERT INTO `relationship` VALUES ('12', '3', '2');
INSERT INTO `relationship` VALUES ('13', '1', '7');
INSERT INTO `relationship` VALUES ('14', '7', '1');
INSERT INTO `relationship` VALUES ('15', '6', '7');
INSERT INTO `relationship` VALUES ('16', '7', '6');
INSERT INTO `relationship` VALUES ('17', '2', '4');
INSERT INTO `relationship` VALUES ('18', '4', '2');
INSERT INTO `relationship` VALUES ('19', '1', '8');
INSERT INTO `relationship` VALUES ('20', '8', '1');
INSERT INTO `relationship` VALUES ('23', '8', '7');
INSERT INTO `relationship` VALUES ('24', '7', '8');
INSERT INTO `relationship` VALUES ('27', '9', '7');
INSERT INTO `relationship` VALUES ('28', '7', '9');
INSERT INTO `relationship` VALUES ('31', '9', '3');
INSERT INTO `relationship` VALUES ('32', '3', '9');
INSERT INTO `relationship` VALUES ('33', '9', '2');
INSERT INTO `relationship` VALUES ('34', '2', '9');
INSERT INTO `relationship` VALUES ('35', '8', '4');
INSERT INTO `relationship` VALUES ('36', '4', '8');
INSERT INTO `relationship` VALUES ('37', '6', '4');
INSERT INTO `relationship` VALUES ('38', '4', '6');
INSERT INTO `relationship` VALUES ('39', '6', '3');
INSERT INTO `relationship` VALUES ('40', '3', '6');
INSERT INTO `relationship` VALUES ('41', '6', '5');
INSERT INTO `relationship` VALUES ('42', '5', '6');
INSERT INTO `relationship` VALUES ('43', '9', '6');
INSERT INTO `relationship` VALUES ('44', '6', '9');
INSERT INTO `relationship` VALUES ('45', '3', '4');
INSERT INTO `relationship` VALUES ('46', '4', '3');
INSERT INTO `relationship` VALUES ('47', '3', '5');
INSERT INTO `relationship` VALUES ('48', '5', '3');
INSERT INTO `relationship` VALUES ('49', '2', '6');
INSERT INTO `relationship` VALUES ('50', '6', '2');
INSERT INTO `relationship` VALUES ('53', '8', '5');
INSERT INTO `relationship` VALUES ('54', '5', '8');
INSERT INTO `relationship` VALUES ('57', '1', '10');
INSERT INTO `relationship` VALUES ('58', '10', '1');
INSERT INTO `relationship` VALUES ('59', '8', '2');
INSERT INTO `relationship` VALUES ('60', '2', '8');
INSERT INTO `relationship` VALUES ('61', '1', '12');
INSERT INTO `relationship` VALUES ('62', '12', '1');
INSERT INTO `relationship` VALUES ('65', '13', '2');
INSERT INTO `relationship` VALUES ('66', '2', '13');
INSERT INTO `relationship` VALUES ('67', '13', '3');
INSERT INTO `relationship` VALUES ('68', '3', '13');
INSERT INTO `relationship` VALUES ('73', '13', '1');
INSERT INTO `relationship` VALUES ('74', '1', '13');
INSERT INTO `relationship` VALUES ('75', '1', '15');
INSERT INTO `relationship` VALUES ('76', '15', '1');

-- ----------------------------
-- Table structure for `specificflag`
-- ----------------------------
DROP TABLE IF EXISTS `specificflag`;
CREATE TABLE `specificflag` (
  `userName` varchar(20) default NULL,
  `specificFlag` varchar(50) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of specificflag
-- ----------------------------
INSERT INTO `specificflag` VALUES ('aaa', '哈哈,人生不如意之事十之八九');

-- ----------------------------
-- Table structure for `userinfo`
-- ----------------------------
DROP TABLE IF EXISTS `userinfo`;
CREATE TABLE `userinfo` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `username` varchar(45) NOT NULL,
  `userpwd` varchar(45) NOT NULL,
  `usersex` varchar(4) NOT NULL,
  `userage` int(10) unsigned NOT NULL,
  `userimage` varchar(100) default NULL,
  `userdownlinemsg` varchar(2000) default NULL,
  `userstate` varchar(1) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of userinfo
-- ----------------------------
INSERT INTO `userinfo` VALUES ('1', 'aaa', '123', '男', '21', '1', null, 'a');
INSERT INTO `userinfo` VALUES ('2', 'bbb', '234', '女', '18', '1', null, 'a');
INSERT INTO `userinfo` VALUES ('3', 'ccc', '345', '男', '22', '3', null, 'a');
INSERT INTO `userinfo` VALUES ('4', 'ddd', '456', '女', '21', '3', null, 'a');
INSERT INTO `userinfo` VALUES ('5', 'eee', '567', '男', '18', '4', null, 'a');
INSERT INTO `userinfo` VALUES ('6', 'fff', '678', '男', '19', '2', null, 'a');
INSERT INTO `userinfo` VALUES ('7', 'vampire', '8528540', '男', '22', '5', null, 'a');
INSERT INTO `userinfo` VALUES ('8', 'muhaha', 'nidaye', '女', '20', '4', null, 'a');
INSERT INTO `userinfo` VALUES ('9', 'nidaye', 'muhaha', '男', '21', '5', null, 'a');
INSERT INTO `userinfo` VALUES ('10', 'homepc', '123456', '女', '21', '3', null, 'a');
INSERT INTO `userinfo` VALUES ('11', 'chenyunpeng', '62511cpy', '男', '21', '2', null, 'a');
INSERT INTO `userinfo` VALUES ('12', 'abcd', '123456', '男', '25', '4', null, 'a');
INSERT INTO `userinfo` VALUES ('13', 'friendsyh', 'friendsyh', '男', '20', '5', null, 'a');
INSERT INTO `userinfo` VALUES ('14', '451694431', '123456', '男', '23', '2', null, 'a');
INSERT INTO `userinfo` VALUES ('15', 'cqlt', 'zx001212', '男', '20', '2', null, 'a');

              2、导入源码

                       在Eclipse中导入源码,修改相关的classpath,笔者使用的是JDK1.7,加了一些新特新

                (登录、注册的时候)。还有外部jar(主要是Mysql驱动包和一些美化包,美化包其实没怎么用)

                       我想这步就不需要笔者多说了吧,有什么问题可以留言问我!

              3、启动服务器

                        在启动服务器之前,我们需要通过运行ServleConfig做一些数据库配置。

                           Java实现局域网聊天软件分享_第4张图片

                        填上自己设置好的数据库的账号和密码

                          

                       之后运行ServerUI类,启动服务器,记住IP,等会客户端要用

                               Java实现局域网聊天软件分享_第5张图片

                  4、启动客户端

                              客户端的启动,首先也要配置信息。

                             Java实现局域网聊天软件分享_第6张图片

                                  

                          接下来运行clientBase下的

                              

                          之后的操作,都非常简单了,登录、注册......读者可以使用aaa 123(用户名  密码)、bbb 234

                    用户进行登录、相互聊天操作。

              运行相关效果图

                             简单的贴点效果图吧,详细的还需读者自己去操作:

                              Java实现局域网聊天软件分享_第7张图片

                             Java实现局域网聊天软件分享_第8张图片

                            Java实现局域网聊天软件分享_第9张图片

                           Java实现局域网聊天软件分享_第10张图片

                      至于其他功能需要读者自己去实践了,要说明的是视频聊天貌似只是在XP才支持。使用的

                     是JMF技术、内置了一个丑陋的音乐播放器。支持皮肤切换功能,读者自行去实践吧。

                      好了就到这里吧,希望各位朋友多多支持,3Q!

                     

                     Tank大战联机版 http://blog.csdn.net/kiritor/article/details/8948608

                     截图、取色功能:http://blog.csdn.net/kiritor/article/details/8708844

   

                     

你可能感兴趣的:(java,聊天,局域网,QQ类似)