【问题标题】:How to make One to one chat application using spring boot and websockets如何使用 spring boot 和 websockets 制作一对一聊天应用程序
【发布时间】:2018-06-08 16:27:41
【问题描述】:
【问题讨论】:
标签:
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 并做了一个有多个聊天室的版本,所以你可以以此为例。