You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CoreAgent.ProtocolClient.Enums;
using CoreAgent.ProtocolClient.ProtocolEngineCore;
using Microsoft.Extensions.Logging;
namespace CoreAgent.ProtocolClient.ProtocolWsClient
{
public partial class ProtocolWsClient
{
#region 连接管理
public void Start()
{
if (_disposed) return;
try
{
_logger.LogInformation($"[{_config.Name}] 尝试连接: {_config.Address}");
SetState(ClientState.Connecting);
_messageManager.Connect(_config.Address, _config.Ssl);
}
catch (Exception ex)
{
_logger.LogError(ex, $"[{_config.Name}] 连接异常: {ex.Message}");
ConnectionError?.Invoke(this, $"无法连接到 {_config.Address}: {ex.Message}");
SetState(ClientState.Error);
}
}
public void Stop()
{
_messageManager.ResetLogGetId();
SetState(ClientState.Stop);
StopTimers();
_protocolLogProcessor.Stop();
_isReady = false;
_logger.LogDebug($"[{_config.Name}] 停止连接");
}
#endregion
}
}