diff --git a/TcpDotNet/BaseClientNode.cs b/TcpDotNet/BaseClientNode.cs index a9f9cd8..9670bb0 100644 --- a/TcpDotNet/BaseClientNode.cs +++ b/TcpDotNet/BaseClientNode.cs @@ -17,6 +17,7 @@ public abstract class BaseClientNode : Node { private readonly ObjectIDGenerator _callbackIdGenerator = new(); private readonly ConcurrentDictionary>> _packetCompletionSources = new(); + private EndPoint? _remoteEP; /// /// Initializes a new instance of the class. @@ -36,8 +37,11 @@ public abstract class BaseClientNode : Node /// /// The with which the client is communicating. /// An error occurred when attempting to access the socket. - /// has been closed. - public EndPoint RemoteEndPoint => BaseSocket.RemoteEndPoint; + public EndPoint RemoteEndPoint + { + get => _remoteEP ??= BaseSocket.RemoteEndPoint; + internal set => _remoteEP = value; + } /// /// Gets the session ID of the client. diff --git a/TcpDotNet/ProtocolClient.cs b/TcpDotNet/ProtocolClient.cs index 79e823a..1294eb8 100644 --- a/TcpDotNet/ProtocolClient.cs +++ b/TcpDotNet/ProtocolClient.cs @@ -91,6 +91,7 @@ public sealed class ProtocolClient : BaseClientNode } IsConnected = true; + RemoteEndPoint = BaseSocket.RemoteEndPoint; State = ClientState.Handshaking; var handshakeRequest = new HandshakeRequestPacket(ProtocolVersion); diff --git a/TcpDotNet/ProtocolListener.Client.cs b/TcpDotNet/ProtocolListener.Client.cs index 153f5a3..2755a31 100644 --- a/TcpDotNet/ProtocolListener.Client.cs +++ b/TcpDotNet/ProtocolListener.Client.cs @@ -16,6 +16,7 @@ public sealed partial class ProtocolListener BaseSocket = socket ?? throw new ArgumentNullException(nameof(socket)); SessionId = Guid.NewGuid(); IsConnected = true; + RemoteEndPoint = socket.RemoteEndPoint; } ///