diff --git a/Telepathy/Server.cs b/Telepathy/Server.cs index 0b4ada7..da12e1c 100644 --- a/Telepathy/Server.cs +++ b/Telepathy/Server.cs @@ -321,7 +321,15 @@ public string GetClientAddress(int connectionId) // find the connection if (clients.TryGetValue(connectionId, out ConnectionState connection)) { - return ((IPEndPoint)connection.client.Client.RemoteEndPoint).Address.ToString(); + TcpClient tcpClient = connection.client; + if (tcpClient == null) return ""; + Socket clientSocket = tcpClient.Client; + if (clientSocket == null) return ""; + IPEndPoint clientEndpoint = (IPEndPoint)clientSocket.RemoteEndPoint; + if (clientEndpoint == null) return ""; + IPAddress ipAddress = clientEndpoint.Address; + if (ipAddress == null) return ""; + return ipAddress.ToString(); } return ""; }