使用基于 Java 的 netty 套接字 io 客户端向所有浏览器发送消息
我目前正在尝试向基于 java 的套接字 io socket.io 客户端的所有浏览器发送消息-netty。但目前它一次仅向一个浏览器发送消息。 片段如下:
public class IOClientListener implements INSIOHandler {
private INSIOClient ioClient=null;
private final static Logger log=LoggerFactory.getLogger(IOClientListener.class);
@Override
public void OnConnect(INSIOClient client) {
System.out.println("A user connected :: " + client.getSessionID());
client.send("Hey you are connected to myhope.com");
}
@Override
public void OnDisconnect(INSIOClient client) {
System.out.println("A user disconnected :: " + client.getSessionID() + " :: hope it was fun");
}
@Override
public void OnMessage(INSIOClient client, String message) {
System.out.println("A message received:: " + message + " :: hope it was fun");
}
@Override
public void OnShutdown() {
}
public INSIOClient getIOClient(){
return this.ioClient;
}
}
我想知道如何使用此客户端广播消息。提前致谢
I'm currently trying to send a message to all the browsers form java based client for socket io socket.io-netty.But currently it is sending message to only one browser at a time.
the snippent is following:
public class IOClientListener implements INSIOHandler {
private INSIOClient ioClient=null;
private final static Logger log=LoggerFactory.getLogger(IOClientListener.class);
@Override
public void OnConnect(INSIOClient client) {
System.out.println("A user connected :: " + client.getSessionID());
client.send("Hey you are connected to myhope.com");
}
@Override
public void OnDisconnect(INSIOClient client) {
System.out.println("A user disconnected :: " + client.getSessionID() + " :: hope it was fun");
}
@Override
public void OnMessage(INSIOClient client, String message) {
System.out.println("A message received:: " + message + " :: hope it was fun");
}
@Override
public void OnShutdown() {
}
public INSIOClient getIOClient(){
return this.ioClient;
}
}
I want to know how to broadcast the message using this client. Thanks in Advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Netty ChannelGroup 来实现此目的
...
有关更多详细信息,请查看 ChannelGroup API 文档
you can use Netty ChannelGroup for this purpose
...
For more detail, have a look on ChannelGroup API Doc