Skip to content

Commit 324892f

Browse files
erwan-jolyclaude
andauthored
Expose RemoteAddress on IChannel for session-IP consumers (#130)
Needed so hosts can correlate a ClientSession to its peer IP without reaching into SuperSocket internals. NetworkChannel resolves it via IPEndPoint.Address; returns null when the underlying session has no routable endpoint. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bbd4302 commit 324892f

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/NosCore.Networking/IChannel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public interface IChannel
1919
/// </summary>
2020
string Id { get; }
2121

22+
/// <summary>
23+
/// Gets the remote peer's IP address as a string, or null if the
24+
/// underlying session has no routable endpoint yet.
25+
/// </summary>
26+
string? RemoteAddress { get; }
27+
2228
/// <summary>
2329
/// Disconnects the channel asynchronously.
2430
/// </summary>

src/NosCore.Networking/NetworkChannel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// -----------------------------------
66

77
using System;
8+
using System.Net;
89
using System.Threading.Tasks;
910
using SuperSocket.Connection;
1011
using SuperSocket.Server.Abstractions.Session;
@@ -32,6 +33,12 @@ public NetworkChannel(IAppSession session)
3233
/// </summary>
3334
public string Id => _session.SessionID;
3435

36+
/// <summary>
37+
/// Gets the remote peer's IP address as a string, or null if the
38+
/// underlying session has no routable endpoint yet.
39+
/// </summary>
40+
public string? RemoteAddress => (_session.RemoteEndPoint as IPEndPoint)?.Address.ToString();
41+
3542
/// <summary>
3643
/// Disconnects the channel asynchronously.
3744
/// </summary>

src/NosCore.Networking/NosCore.Networking.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<RepositoryUrl>https://github.com/NosCoreIO/NosCore.Networking.git</RepositoryUrl>
1313
<PackageIconUrl></PackageIconUrl>
1414
<PackageTags>nostale, noscore, nostale private server source, nostale emulator</PackageTags>
15-
<Version>7.1.0</Version>
15+
<Version>7.2.0</Version>
1616
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1717
<Description>NosCore Networking</Description>
1818
<PackageLicenseExpression>MIT</PackageLicenseExpression>

0 commit comments

Comments
 (0)