基于Springboot+websocket的web聊天项目(论文+程序设计源码+数据库文件)

摘要:随着互联网的快速发展,网络聊天工具已经作为一种重要的信息交流工具,受到越来越多的网民的青睐。目前,出现了很多非常不错的聊天工具,其中应用比较广泛的有 Netmeeting 、腾讯 QQ、MSN-Messager等等。该系统开发主要包括一个网络聊天服务器程序和一个网络聊天客户程序两个方面。前者通过 Socket 套接字建立服务器,服务器能读取、转发客户端发来信息,并能刷新用户列表。后者通过与服务器建立连接,来进行客户端与客户端的信息交流。其中用到了局域网通信机制的原理,通过直接继承 Thread 类来建立多线程。开发中利用了计算机网络编程的基本理论知识 , 如 TCP/IP 协议、客户端 / 服务器端模式( Client/Server 模式)、网络编程的设计方法等。在网络编程中对信息的读取、发送,是利用流来实现信息的交换,其中介绍了对实现一个系统的信息流的分析,包含了一些基本的软件工程的方法。经过分析这些情况, 该局域网聊天工具采用 Eclipse 为基本开发环境和 java语言进行编写,首先可在短时间内建立系统应用原型,然后,对初始原型系统进行不断修正和改进,直到形成可行系统
关键词: 聊天; springboot;websocket;mysql

Abstract: with the rapid development of the Internet, online chat tool has been an important information exchange tool, favored by more and more Internet users. At present, there are many very good chat tools, among which NetMeeting, Tencent QQ, MSN Messenger and so on are widely used. The development of the system mainly includes a network chat server program and a network chat client program. The former establishes the server through socket socket, the server can read and forward the information from the client, and refresh the user list. The latter establishes a connection with the server to exchange information between clients. The principle of local area network communication mechanism is used, and multithreading is established by directly inheriting thread class. The basic theoretical knowledge of computer network programming is used in the development, such as TCP / IP protocol, client / server mode, design method of network programming, etc. In network programming, the reading and sending of information is to realize the exchange of information by using flow. This paper introduces the analysis of the information flow of a system, including some basic software engineering methods. After analyzing these situations, the LAN chat tool is written with eclipse as the basic development environment and Java language. Firstly, the system application prototype can be established in a short time, and then the initial prototype system is continuously modified and improved until a feasible system is formed

Key words: chat; springboot; websocket; mysql

目录
1 绪论 3
1.1 项目开发背景 3
1.2 项目开发意义 3
1.3 项目主要的内容 4
2 相关技术介绍及系统环境开发条件 4
2.1相关技术介绍 4
2.2系统环境开发条件 5
3 系统的需求分析与设计 6
3.1可行性分析 6
3.2需求分析 7
3.2.1系统总体概述 7
3.2.2功能性需求 7
3.2.3非功能性需求 8
3.3概要设计 8
服务端结构 8
客户端结构 9
3.2.5系统ER图设计 10
3.3 数据库设计 11
3.3.1数据库设计的原则 11
3.3.2数据库ER图设计 11
3.3.3数据库表的设计 11
4系统功能模块实现 12
4.1 登陆功能模块实现 12
4.2 聊天页面功能实现 14
4.2日志功能模块 17
5 系统测试 17
5.1系统调试的目的和意义 17
5.2功能测试用例 18
6总结 19
参考文献: 19
致 谢 20
在这里插入图片描述
在这里插入图片描述

 private static ChatMsgService chatMsgService;
    // 注入的时候,给类的 service 注入
    @Autowired
    public void setChatService(ChatMsgService chatService) {
        ChatWebSocket.chatMsgService = chatService;
    }

    //静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。
    private static int onlineCount = 0;
    //concurrent包的线程安全Set,用来存放每个客户端对应的MyWebSocket对象。若要实现服务端与单一客户端通信的话,可以使用Map来存放,其中Key可以为用户标识
    private static ConcurrentHashMap<String, ChatWebSocket> webSocketSet = new ConcurrentHashMap<String, ChatWebSocket>();
    //与某个客户端的连接会话,需要通过它来给客户端发送数据
    private Session WebSocketsession;
    //当前发消息的人员编号
    private String userno = "";
 /**
     * 连接关闭调用的方法
     */
    @OnClose
    public void onClose() {
        if (!userno.equals("")) {
            webSocketSet.remove(userno); //从set中删除
            subOnlineCount();     //在线数减1
            //System.out.println("有一连接关闭!当前在线人数为" + getOnlineCount());
        }
    }


    /**
     * 收到客户端消息后调用的方法
     *
     * @param chatmsg 客户端发送过来的消息
     * @param session 可选的参数
     */
    @SuppressWarnings("unused")
	@OnMessage
    public void onMessage(String chatmsg, Session session) {
        JSONObject jsonObject = JSONObject.parseObject(chatmsg);
        //给指定的人发消息
        sendToUser(jsonObject.toJavaObject(ChatMsg.class));
        //sendAll(message);
    }


    /**
     * 给指定的人发送消息
     *
     * @param chatMsg 消息对象
     */
    public void sendToUser(ChatMsg chatMsg) {
        String reviceUserid = chatMsg.getReciveuserid();
        String sendMessage = chatMsg.getSendtext();
        sendMessage= EmojiFilter.filterEmoji(sendMessage);//过滤输入法输入的表情
        chatMsgService.InsertChatMsg(new ChatMsg().setMsgtype(chatMsg.getMsgtype()).setReciveuserid(reviceUserid).setSenduserid(userno).setSendtext(sendMessage));
        try {
            if (webSocketSet.get(reviceUserid) != null) {
                webSocketSet.get(reviceUserid).sendMessage(userno+"|"+sendMessage);
            }else{
                webSocketSet.get(userno).sendMessage("0"+"|"+"当前用户不在线");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

基于Springboot+websocket的web聊天项目(论文+程序设计源码+数据库文件):点击下载

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员小蛋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值