【问题标题】:How to make One to one chat application using spring boot and websockets如何使用 spring boot 和 websockets 制作一对一聊天应用程序
【发布时间】:2018-06-08 16:27:41
【问题描述】:

谁能告诉我“如何使用 spring boot 和 websockets 制作一对一的聊天应用程序” 我有一个示例,使用下面的 spring boot 和 websockets 链接,该消息将发送给所有已连接的用户。 https://www.callicoder.com/spring-boot-websocket-chat-example/

我想让应用程序像客户端和管理员之间的聊天一样,每个客户端和管理员之间的对话不能转到其他客户端。

【问题讨论】:

    标签: spring-boot websocket


    【解决方案1】:

    我意识到你可能已经离开了,但为了其他人的利益

    一种简单的方法是让客户端从消息中读取收件人并确定消息是否是针对他们的。在您的 chatMessage 模型中,为发件人和收件人添加字段。然后在客户端上你会有类似的东西

    // RECIPIENT IS ME OR IS NULL THEN MESSAGE IS FOR ME (NULL BEING EVERYONE)
    if (chatMessage.recipient === this.userName || chatMessage.recipient == NULL) 
       { 
        show the message 
    } else 
    { 
        ignore it 
    } 
    

    或者,您可以为每个用户创建队列。有人在 github 上 fork https://github.com/ddycai/spring-boot-chatrooms 并做了一个有多个聊天室的版本,所以你可以以此为例。

    【讨论】:

      猜你喜欢
      • 2021-03-26
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 2017-07-26
      • 2014-10-18
      • 2013-12-07
      • 2014-07-08
      • 1970-01-01
      相关资源
      最近更新 更多