/// <summary> /// Start a client thread to send and receive data. /// The caller is warned when a reply is received by a call to the specified function (<see cref="SendAsyncType"/>). /// </summary> /// <param name="sendAsync">Settings to start the thread</param> /// <param name="request">The request as bytes array</param> /// <param name="addSizeHeader">Indicates whether or not adding a size header when sending the request</param> /// <param name="lineExchanges">Indicates whether (true) or not (false) the exchanges complete by a new line, not using the size header. /// If set to true no buffer size is never used during the exchanges (present or not) and the EOT is always represented by a CR+LF. /// Setting this parameter to true supersedes the addSizeHeader one</param> /// <param name="EOT"></param> /// <returns>A <see cref="CThread"/> object if the thread has been started, null otherwise</returns> public static CThread SendAsync(SendAsyncType sendAsync, byte[] request, bool addSizeHeader, bool lineExchanges = false, string EOT = CStreamIO.CRLF) { if (null == sendAsync || null == sendAsync.Settings || !sendAsync.Settings.IsValid || null == request || 0 == request.Length) { return(null); } try { // prepare working settings ClientThreadType threadParams = new ClientThreadType() { SendAsync = sendAsync, Request = request, AddSizeHeader = addSizeHeader, ClientOnly = null == sendAsync.OnReply, LineExchanges = lineExchanges, EOT = EOT, }; // prepare the thread object CThread thread = new CThread(); //if (thread.Start(SendAsyncThreadMethod, sendAsync.ThreadData, threadParams, null, sendAsync.OnTerminate, true)) if (thread.Start(SendAsyncThreadMethod, sendAsync.ThreadData, threadParams, null, true)) { return(thread); } else { thread = null; } } catch (Exception ex) { CLog.AddException($"{MethodBase.GetCurrentMethod().Module.Name}.{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}", ex); } return(null); }
/// <summary> /// Refer to <see cref="SendAsync(SendAsyncType, byte[], bool, bool, string)"/> /// This function prevents using any size header, using CR+LF as an EOT /// </summary> /// <param name="sendAsync"></param> /// <param name="request"></param> /// <param name="EOT"></param> /// <returns></returns> public static CThread SendAsyncLine(SendAsyncType sendAsync, string request, string EOT = CStreamIO.CRLF) { return(SendAsync(sendAsync, Encoding.UTF8.GetBytes(request), false, true, EOT)); }
/// <summary> /// Refer to <see cref="SendAsync(SendAsyncType, byte[], bool, bool, string)"/> /// </summary> /// <param name="sendAsync"></param> /// <param name="request"></param> /// <returns></returns> public static CThread SendAsync(SendAsyncType sendAsync, string request) { return(SendAsync(sendAsync, Encoding.UTF8.GetBytes(request), true, false)); }
public RestMessageHandler(SendAsyncType sendAsync) { _sendAsync = sendAsync; }
private static HttpClient MakeHttpClient(SendAsyncType sendAsync) { return(new HttpClient(new RestMessageHandler(sendAsync), true)); }
public RestTransport(SendAsyncType sendAsync) : this(MakeHttpClient(sendAsync)) { }