简体   繁体   English

如何查找从 ChannelGroup 中的特定主机名连接的所有客户端

[英]How to find all the clients that connected from specific hostname in ChannelGroup

I am learning about the.netty framework and Google protobuf, so now I am writing some simple server and client applications.我正在学习 .netty 框架和 Google protobuf,所以现在我正在编写一些简单的服务器和客户端应用程序。

I wrote a server based on the SecureChat example that come from.netty and I want to write a method that return all the channels that connected from a specific ip (no matter what port).我基于来自.netty 的 SecureChat 示例编写了一个服务器,我想编写一个方法来返回从特定 ip(无论什么端口)连接的所有通道。 I have a ChannelGroup that holds all the connected channels and I thought about using the write method - write(Object message, SocketAddress remoteAddress), but in the SocketAddress class I have to insert port.我有一个包含所有已连接通道的 ChannelGroup,我考虑过使用写入方法 - write(Object message, SocketAddress remoteAddress),但在 SocketAddress class 中我必须插入端口。

So I thought about other ways but the only way I found working is using a for loop, but there is another ways?所以我考虑了其他方法,但我发现唯一可行的方法是使用 for 循环,但还有其他方法吗? Some way that will give me better performance?某种方式可以给我更好的表现?

Thanks, BBLN.谢谢,BBLN。

You could have your own ChannelGroup implementation which supports this.您可以拥有自己的支持此功能的 ChannelGroup 实现。 For this you could have a Map of Channels that are using the .netAddress of the Channel as key.为此,您可以使用 Map 的频道,这些频道使用频道的 .netAddress 作为键。 So you will be able to lookup all Channels by IP in a fast way.因此,您将能够快速查找 IP 的所有频道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从服务器向所有连接的客户端发送消息 - send message from server to all connected clients 如何在Java中的多客户端/服务器应用程序中查找所有已连接客户端的IP地址? - how to find ip address of all connected clients in multi-client/server application in java? 显示从服务器到所有连接的客户端的在线用户 - Display online users from server to all connected clients 如何在Java中添加聊天应用程序上连接的所有客户端的列表? - how to add a list of all the clients connected on a chat application in Java? 如何为连接到服务器的所有客户端更新 JButton? - How can I have a JButton update for all clients connected to a server? 如何找到一个数组中的所有连接的数字? - How to find all connected numbers in an array? 向所有连接的Web套接字客户端发送消息 - Send message to all connected web socket clients 节俭:向连接到服务器的所有客户端发送消息 - Thrift: Send a message to all clients connected to the server 服务器向所有连接的客户端发送消息 - Server send message to all connected clients 在使用多线程的同时如何将接收到的数据从连接的客户端分发到其他连接的客户端? - How to distribute received data from a connected client to other connected clients while making use of mulithreading?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM