/// <summary> /// Attempt a connection. /// </summary> /// <returns>True if successful, false otherwise</returns> /// <remarks>If it fail, check the LastConnectError property to see the details of the failure.</remarks> public bool Connect() { try { if (Disposed) { RestartSocket(); } Client.Connect(ServerAddress, Port); LastConnectError = null; InfoHandler.EnableSsl = SSLTargetHost != null; InfoHandler.SSLTargetHost = SSLTargetHost; InfoHandler.IsLengthInOneFrame = IsLengthInOneFrame; InfoHandler.StartReceive(); return(true); } catch (Exception e) { LastConnectError = e; return(false); } }
/// <summary> /// Attempt a connection. /// </summary> /// <returns>True if successful, false otherwise</returns> /// <remarks>If it fail, check the LastConnectError property to see the details of the failure.</remarks> public async Task <bool> ConnectAsync() { Task task = null; try { if (Disposed) { RestartSocket(); } task = Client.ConnectAsync(ServerAddress, Port); await task; LastConnectError = null; InfoHandler.EnableSsl = SSLTargetHost != null; InfoHandler.SSLTargetHost = SSLTargetHost; InfoHandler.IsLengthInOneFrame = IsLengthInOneFrame; InfoHandler.StartReceive(); return(true); } catch { LastConnectError = task != null ? task.Exception : null; return(false); } }