Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

一对一发消息应该怎样做 #24

Closed
GitBiao opened this issue Jan 22, 2019 · 5 comments
Closed

一对一发消息应该怎样做 #24

GitBiao opened this issue Jan 22, 2019 · 5 comments

Comments

@GitBiao
Copy link

GitBiao commented Jan 22, 2019

想用这个做im,刚刚其他人的issuer说主动给client发消息,要接入kafka?

@YeautyYE
Copy link
Owner

不需要,用以下方法即可
session.sendText("Hello Netty!");

@GitBiao
Copy link
Author

GitBiao commented Jan 22, 2019

不需要,用以下方法即可
session.sendText("Hello Netty!");
这样应该不行的,就是a对b发消息,b对a发消息
a发了给b消息,触发的是a的onmessage,所以session是a的 ,sendText是发回给a了

@YeautyYE
Copy link
Owner

不需要,用以下方法即可
session.sendText("Hello Netty!");
这样应该不行的,就是a对b发消息,b对a发消息
a发了给b消息,触发的是a的onmessage,所以session是a的 ,sendText是发回给a了

Client对Server发消息,触发@OnMessage事件(Server接收到Client的消息),session是Client的会话实例.
session.sendText("Hello Netty!"); 则是Server主动向Client发消息.

@GitBiao
Copy link
Author

GitBiao commented Jan 22, 2019

现在我的session实例放内存里了
private Session session; private String sid; private static CopyOnWriteArraySet<MyWebSocket> webSocketSet = new CopyOnWriteArraySet<>();
然后发消息的时候循环找出相应的session实例,这样连接数多的时候,程序估计就撑不住了,有没有什么好的方法

@YeautyYE
Copy link
Owner

现在我的session实例放内存里了
private Session session; private String sid; private static CopyOnWriteArraySet<MyWebSocket> webSocketSet = new CopyOnWriteArraySet<>();
然后发消息的时候循环找出相应的session实例,这样连接数多的时候,程序估计就撑不住了,有没有什么好的方法

用map,通过key去找

@GitBiao GitBiao closed this as completed Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants