/// <summary> /// Send a packet with specified timeout /// </summary> /// <param name="packet"></param> /// <param name="remoteEndpoint"></param> /// <param name="timeout"></param> /// <returns></returns> public async Task <IRadiusPacket> SendPacketAsync(IRadiusPacket packet, IPEndPoint remoteEndpoint, TimeSpan timeout) { await _client.ConnectAsync(remoteEndpoint.Address, remoteEndpoint.Port); var sslStream = new SslStream(_client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate)); await sslStream.AuthenticateAsClientAsync("radsecserver", _certs, SslProtocols.Tls12, true); var packetBytes = packet.GetBytes(_dictionary); await sslStream.WriteAsync(packetBytes, 0, packetBytes.Length); if (RadiusPacket.TryParsePacketFromStream(sslStream, out var responsePacket, _dictionary, packet.SharedSecret)) { _client.Close(); return(responsePacket); } _client.Close(); return(null); }