diff --git a/src/HPSocket.Net/Base/Server.cs b/src/HPSocket.Net/Base/Server.cs index 778ac0d2bb122a919394677f716ef96555c1dcce..02594760ddcd1cb61c6e28247c6938005fe0c622 100644 --- a/src/HPSocket.Net/Base/Server.cs +++ b/src/HPSocket.Net/Base/Server.cs @@ -5,6 +5,9 @@ using System.Runtime.InteropServices; using System.Text; #if !NET20 && !NET30 && !NET35 using System.Threading.Tasks; +using System.Collections.Concurrent; +#else +using System.Collections.Generic; #endif namespace HPSocket.Base @@ -428,6 +431,27 @@ namespace HPSocket.Base return obj == null ? default : (T)obj; } + #if NET20 || NET30 || NET35 + /// + /// 获取所有扩展数据 + /// + /// + public Dictionary GetAllExtra() + { + return ExtraData.GetAll(); + } + #else + /// + /// 获取所有扩展数据 + /// + /// + public ConcurrentDictionary GetAllExtra() + { + return ExtraData.GetAll(); + } + #endif + + /// public bool RemoveExtra(IntPtr connId) => ExtraData.Remove(connId); diff --git a/src/HPSocket.Net/Common/ExtraData.cs b/src/HPSocket.Net/Common/ExtraData.cs index 33c9f1da577a573c95f10731dcee4ad6d00ec870..21e38e62397a06fc4d6d3c9409f3b12ca670f72a 100644 --- a/src/HPSocket.Net/Common/ExtraData.cs +++ b/src/HPSocket.Net/Common/ExtraData.cs @@ -45,6 +45,17 @@ namespace HPSocket } + /// + /// 获取所有扩展数据 + /// + /// + public Dictionary GetAll() + { + return _dict; + } + + + /// /// 设置附加数据 /// @@ -137,6 +148,15 @@ namespace HPSocket } } + /// + /// 获取所有扩展数据 + /// + /// + public ConcurrentDictionary GetAll() + { + return _dict; + } + /// /// 设置附加数据 /// diff --git a/src/HPSocket.Net/HPSocket.Net.xml b/src/HPSocket.Net/HPSocket.Net.xml index 6321fd7aef7dfec46119bd481b27552862221a9a..a8fdbddde796fd86b0375b300745d7bcf812bee0 100644 --- a/src/HPSocket.Net/HPSocket.Net.xml +++ b/src/HPSocket.Net/HPSocket.Net.xml @@ -984,6 +984,12 @@ + + + 获取所有扩展数据 + + + @@ -1510,6 +1516,12 @@ + + + 获取所有扩展数据 + + + 设置附加数据 @@ -4405,6 +4417,12 @@ + + + 获取所有扩展数据 + + + 删除附加数据 @@ -5970,6 +5988,13 @@ 获取是否启动 + + + 获取指定连接的子协议 + + + + 获取连接的http会话信息 @@ -8361,6 +8386,9 @@ + + + diff --git a/src/HPSocket.Net/IServer.cs b/src/HPSocket.Net/IServer.cs index 79affad8de27fd977391794d5d85aa8397dba035..6cf00124d9d3b3b66db3f164da3a62ce6a396f87 100644 --- a/src/HPSocket.Net/IServer.cs +++ b/src/HPSocket.Net/IServer.cs @@ -2,6 +2,9 @@ using System.Collections.Generic; #if !NET20 && !NET30 && !NET35 using System.Threading.Tasks; +using System.Collections.Concurrent; +#else +using System.Collections.Generic; #endif namespace HPSocket @@ -336,6 +339,20 @@ namespace HPSocket /// T GetExtra(IntPtr connId); + #if NET20 || NET30 || NET35 + /// + /// 获取所有扩展数据 + /// + /// + Dictionary GetAllExtra(); + #else + /// + /// 获取所有扩展数据 + /// + /// + ConcurrentDictionary GetAllExtra(); + #endif + /// /// 删除附加数据 /// diff --git a/src/HPSocket.Net/IWebSocketServer.cs b/src/HPSocket.Net/IWebSocketServer.cs index 658e17fdfd6d4e43a2664848749ba44d7585fbfc..44ab2da34903bbd2b605ed66c4a91d94e3fe3145 100644 --- a/src/HPSocket.Net/IWebSocketServer.cs +++ b/src/HPSocket.Net/IWebSocketServer.cs @@ -26,6 +26,13 @@ namespace HPSocket #region 服务器方法 + /// + /// 获取指定连接的子协议 + /// + /// + /// + string GetSubProtocol(IntPtr connId); + /// /// 获取连接的http会话信息 /// diff --git a/src/HPSocket.Net/WebSocket/WebSocketServer.cs b/src/HPSocket.Net/WebSocket/WebSocketServer.cs index f0b49cce4d13428400181608f11647c7fe6c2ec3..6aa5bed5b24302f4858d7c62214ee00bfd14ee28 100644 --- a/src/HPSocket.Net/WebSocket/WebSocketServer.cs +++ b/src/HPSocket.Net/WebSocket/WebSocketServer.cs @@ -222,6 +222,13 @@ namespace HPSocket.WebSocket /// public bool HasStarted => _httpServer.HasStarted; + /// + public string GetSubProtocol(IntPtr connId) + { + var session = _wsSessions.Get(connId); + return session != null ? session.SecWebSocketProtocol : ""; + } + /// public HttpSession GetHttpSession(IntPtr connId) {