Private chat with SignalR

2019-03-09 18:19发布

I would like to know if is possible to create a chat for private conversation like gmail chat or hotmail.. How can I ensure that only client A talks with client B? How can I ensure that only logged clients can talk?

标签: signalr
4条回答
SAY GOODBYE
2楼-- · 2019-03-09 18:38

Look at ChatWithTracking in Basic chat sample, that's a great starting point for IM setup

p.s: updated the link; using a search query in case they change the repo structure again

查看更多
你好瞎i
3楼-- · 2019-03-09 18:42

Each client connecting to a hub passes a unique connection id. You can retrieve this value in the Context.ConnectionId property of the hub context. If your application needs to map a user to the connection id and persist that mapping, you can use one of the following:

  1. In-memory storage, such as a dictionary
  2. SignalR group for each user
  3. Permanent, external storage, such as a database table or Windows Azure table

http://www.asp.net/signalr/overview/hubs-api/mapping-users-to-connections

查看更多
我只想做你的唯一
4楼-- · 2019-03-09 18:54

Sure, you can create a unique "Group" each time a user initiates a chat with another user (or set of users). Then when you send messages to that group only those users would receive the message. You could also layer more security in front of sending messages to a group to ensure that the person sending the message is allowed to send a message to that group.

查看更多
甜甜的少女心
5楼-- · 2019-03-09 18:54
登录 后发表回答