You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
866 B
32 lines
866 B
using DotNetty.Common.Utilities;
|
|
using DotNetty.Transport.Channels;
|
|
|
|
namespace HybirdFrameworkServices.Netty;
|
|
|
|
public static class ChannelUtils
|
|
{
|
|
private static readonly AttributeKey<IoSession> SessionKey = AttributeKey<IoSession>.ValueOf("session");
|
|
|
|
/**
|
|
* 添加新的会话
|
|
* @param channel
|
|
* @param session
|
|
* @return
|
|
*/
|
|
public static void AddChannelSession(IChannel channel, IoSession session)
|
|
{
|
|
IAttribute<IoSession> attribute = channel.GetAttribute(SessionKey);
|
|
attribute.Set(session);
|
|
}
|
|
|
|
public static IoSession GetSessionBy(IChannel channel)
|
|
{
|
|
IAttribute<IoSession> sessionAttr = channel.GetAttribute(SessionKey);
|
|
return sessionAttr.Get();
|
|
}
|
|
|
|
public static String GetIp(IChannel channel)
|
|
{
|
|
return channel.RemoteAddress.Serialize().ToString();
|
|
}
|
|
} |