using DotNetty.Common.Utilities; using DotNetty.Transport.Channels; namespace HybirdFrameworkDriver.TcpServer; public static class ChannelUtils { private static readonly AttributeKey SessionKey = AttributeKey.ValueOf("session"); /** * 添加新的会话 * @param channel * @param session * @return */ public static void AddChannelSession(IChannel channel, IoSession session) { IAttribute attribute = channel.GetAttribute(SessionKey); attribute.Set(session); } public static IoSession GetSessionBy(IChannel channel) { IAttribute sessionAttr = channel.GetAttribute(SessionKey); return sessionAttr.Get(); } public static String GetIp(IChannel channel) { return channel.RemoteAddress.Serialize().ToString(); } }