Dreamine.Communication.Sockets 1.0.2
Dreamine.Communication.Sockets 통신 기능과 관련 API를 제공합니다.
로딩중...
검색중...
일치하는것 없음
Dreamine.Communication.Sockets.Clients.TcpClientTransport 클래스 참조sealed

더 자세히 ...

Dreamine.Communication.Sockets.Clients.TcpClientTransport에 대한 상속 다이어그램 :
Dreamine.Communication.Sockets.Clients.TcpClientTransport에 대한 협력 다이어그램:

Public 멤버 함수

 TcpClientTransport (TcpClientTransportOptions options)
 TcpClientTransport (TcpClientTransportOptions options, IMessageProtocolAdapter protocolAdapter, IMessageFrameCodec frameCodec)
async Task ConnectAsync (CancellationToken cancellationToken=default)
async Task DisconnectAsync (CancellationToken cancellationToken=default)
async Task SendAsync (MessageEnvelope message, CancellationToken cancellationToken=default)
async ValueTask DisposeAsync ()

속성

ConnectionState State [get]
TransportKind Kind [get]

이벤트

EventHandler< MessageEnvelope >? MessageReceived

Private 멤버 함수

async Task ReceiveLoopAsync (CancellationToken cancellationToken)
void CleanupClient ()
void SetState (ConnectionState state)

정적 Private 멤버 함수

static void ValidateOptions (TcpClientTransportOptions options)

Private 속성

readonly TcpClientTransportOptions _options
readonly IMessageProtocolAdapter _protocolAdapter
readonly IMessageFrameCodec _frameCodec
TcpClient? _client
CancellationTokenSource? _receiveLoopCts
Task? _receiveLoopTask
int _state = (int)ConnectionState.Disconnected

상세한 설명

TCP 클라이언트 연결에서 구성 가능한 프레임과 프로토콜로 메시지를 송수신합니다.

TcpClientTransport.cs 파일의 20 번째 라인에서 정의되었습니다.

생성자 & 소멸자 문서화

◆ TcpClientTransport() [1/2]

Dreamine.Communication.Sockets.Clients.TcpClientTransport.TcpClientTransport ( TcpClientTransportOptions options)
inline

기본 Dreamine JSON 프로토콜과 길이 접두사 프레임으로 TCP 클라이언트를 초기화합니다.

매개변수
options서버 주소, 버퍼 및 연결 제한 시간 설정입니다.

TcpClientTransport.cs 파일의 103 번째 라인에서 정의되었습니다.

104 : this(
105 options,
106 new DreamineEnvelopeProtocolAdapter(),
107 new LengthPrefixedMessageFrameCodec())
108 {
109 }

◆ TcpClientTransport() [2/2]

Dreamine.Communication.Sockets.Clients.TcpClientTransport.TcpClientTransport ( TcpClientTransportOptions options,
IMessageProtocolAdapter protocolAdapter,
IMessageFrameCodec frameCodec )
inline

TCP 설정과 사용자 지정 프로토콜 및 프레임 코덱으로 클라이언트를 초기화합니다.

매개변수
options서버 주소, 버퍼 및 연결 제한 시간 설정입니다.
protocolAdapter메시지와 외부 페이로드를 변환할 어댑터입니다.
frameCodecTCP 스트림의 메시지 경계를 처리할 코덱입니다.
예외
ArgumentNullExceptionoptions , protocolAdapter 또는 frameCodecnull인 경우 발생합니다.

TcpClientTransport.cs 파일의 151 번째 라인에서 정의되었습니다.

155 {
156 _options = options ?? throw new ArgumentNullException(nameof(options));
157 _protocolAdapter = protocolAdapter ?? throw new ArgumentNullException(nameof(protocolAdapter));
158 _frameCodec = frameCodec ?? throw new ArgumentNullException(nameof(frameCodec));
159
160 ValidateOptions(_options);
161 }

다음을 참조함 : _frameCodec, _options, _protocolAdapter, ValidateOptions().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

멤버 함수 문서화

◆ CleanupClient()

void Dreamine.Communication.Sockets.Clients.TcpClientTransport.CleanupClient ( )
inlineprivate

정리 예외를 전파하지 않고 TCP 클라이언트를 닫고 해제합니다.

TcpClientTransport.cs 파일의 528 번째 라인에서 정의되었습니다.

529 {
530 try
531 {
532 _client?.Close();
533 }
534 catch
535 {
536 }
537
538 try
539 {
540 _client?.Dispose();
541 }
542 catch
543 {
544 }
545
546 _client = null;
547 }

다음을 참조함 : _client.

다음에 의해서 참조됨 : ConnectAsync(), DisconnectAsync(), ReceiveLoopAsync(), SendAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ConnectAsync()

async Task Dreamine.Communication.Sockets.Clients.TcpClientTransport.ConnectAsync ( CancellationToken cancellationToken = default)
inline

제한 시간 내에 TCP 서버에 연결하고 백그라운드 수신 루프를 시작합니다.

매개변수
cancellationToken연결 취소 요청을 감시하는 토큰입니다.
반환값
비동기 TCP 연결 작업입니다.
예외
OperationCanceledException사용자 취소 또는 연결 제한 시간 만료 시 발생할 수 있습니다.

TcpClientTransport.cs 파일의 225 번째 라인에서 정의되었습니다.

226 {
227 if (State is ConnectionState.Connected or ConnectionState.Connecting)
228 {
229 return;
230 }
231
232 SetState(ConnectionState.Connecting);
233
234 try
235 {
236 CleanupClient();
237
238 _client = new TcpClient
239 {
240 ReceiveBufferSize = _options.ReceiveBufferSize,
241 SendBufferSize = _options.SendBufferSize
242 };
243
244 using var timeoutCts = new CancellationTokenSource(_options.ConnectTimeoutMs);
245 using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(
246 cancellationToken,
247 timeoutCts.Token);
248
249 await _client.ConnectAsync(_options.Host, _options.Port, linkedCts.Token)
250 .ConfigureAwait(false);
251
252 SetState(ConnectionState.Connected);
253
254 _receiveLoopCts = new CancellationTokenSource();
255 _receiveLoopTask = Task.Run(
256 () => ReceiveLoopAsync(_receiveLoopCts.Token),
257 _receiveLoopCts.Token);
258 }
259 catch
260 {
261 SetState(ConnectionState.Faulted);
262 CleanupClient();
263
264 throw;
265 }
266 }

다음을 참조함 : _client, _options, _receiveLoopCts, _receiveLoopTask, CleanupClient(), ReceiveLoopAsync(), SetState(), State.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ DisconnectAsync()

async Task Dreamine.Communication.Sockets.Clients.TcpClientTransport.DisconnectAsync ( CancellationToken cancellationToken = default)
inline

수신 루프를 중지하고 TCP 클라이언트 연결을 닫습니다.

매개변수
cancellationToken정리 후 연결 해제 취소 여부를 확인하는 토큰입니다.
반환값
비동기 연결 해제 작업입니다.

TcpClientTransport.cs 파일의 292 번째 라인에서 정의되었습니다.

293 {
294 if (State == ConnectionState.Disconnected)
295 {
296 return;
297 }
298
299 SetState(ConnectionState.Disconnecting);
300
301 _receiveLoopCts?.Cancel();
302
303 CleanupClient();
304
305 if (_receiveLoopTask is not null)
306 {
307 try
308 {
309 await _receiveLoopTask.ConfigureAwait(false);
310 }
311 catch (OperationCanceledException)
312 {
313 }
314 catch (ObjectDisposedException)
315 {
316 }
317 catch (SocketException)
318 {
319 }
320 catch (IOException)
321 {
322 }
323 }
324
325 _receiveLoopCts?.Dispose();
326 _receiveLoopCts = null;
327 _receiveLoopTask = null;
328
329 cancellationToken.ThrowIfCancellationRequested();
330
331 SetState(ConnectionState.Disconnected);
332 }

다음을 참조함 : _receiveLoopCts, _receiveLoopTask, CleanupClient(), SetState(), State.

다음에 의해서 참조됨 : DisposeAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ DisposeAsync()

async ValueTask Dreamine.Communication.Sockets.Clients.TcpClientTransport.DisposeAsync ( )
inline

TCP 연결과 수신 루프 리소스를 비동기적으로 해제합니다.

반환값
비동기 리소스 해제 작업입니다.

TcpClientTransport.cs 파일의 426 번째 라인에서 정의되었습니다.

427 {
428 await DisconnectAsync().ConfigureAwait(false);
429 }

다음을 참조함 : DisconnectAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ ReceiveLoopAsync()

async Task Dreamine.Communication.Sockets.Clients.TcpClientTransport.ReceiveLoopAsync ( CancellationToken cancellationToken)
inlineprivate

TCP 스트림에서 프레임을 계속 읽어 메시지로 디코딩하고 수신 이벤트를 발생시킵니다.

매개변수
cancellationToken수신 루프 종료 토큰입니다.
반환값
백그라운드 수신 루프 작업입니다.

TcpClientTransport.cs 파일의 455 번째 라인에서 정의되었습니다.

456 {
457 if (_client is null)
458 {
459 return;
460 }
461
462 try
463 {
464 var stream = _client.GetStream();
465
466 while (!cancellationToken.IsCancellationRequested &&
467 State == ConnectionState.Connected)
468 {
469 var payload = await _frameCodec.ReadFrameAsync(stream, cancellationToken)
470 .ConfigureAwait(false);
471
472 if (payload is null)
473 {
474 break;
475 }
476
477 var message = _protocolAdapter.Decode(payload);
478 MessageReceived?.Invoke(this, message);
479 }
480
481 if (!cancellationToken.IsCancellationRequested &&
482 State == ConnectionState.Connected)
483 {
484 SetState(ConnectionState.Disconnected);
485 CleanupClient();
486 }
487 }
488 catch (OperationCanceledException)
489 {
490 }
491 catch (ObjectDisposedException)
492 {
493 }
494 catch (SocketException)
495 {
496 if (!cancellationToken.IsCancellationRequested)
497 {
498 SetState(ConnectionState.Faulted);
499 CleanupClient();
500 }
501 }
502 catch (IOException)
503 {
504 if (!cancellationToken.IsCancellationRequested)
505 {
506 SetState(ConnectionState.Faulted);
507 CleanupClient();
508 }
509 }
510 catch
511 {
512 if (!cancellationToken.IsCancellationRequested)
513 {
514 SetState(ConnectionState.Faulted);
515 CleanupClient();
516 }
517 }
518 }

다음을 참조함 : _client, _frameCodec, _protocolAdapter, CleanupClient(), MessageReceived, SetState(), State.

다음에 의해서 참조됨 : ConnectAsync().

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ SendAsync()

async Task Dreamine.Communication.Sockets.Clients.TcpClientTransport.SendAsync ( MessageEnvelope message,
CancellationToken cancellationToken = default )
inline

메시지를 외부 프로토콜과 프레임 형식으로 인코딩해 TCP 서버로 전송합니다.

매개변수
message전송할 메시지입니다.
cancellationToken프레임 쓰기 취소 요청을 감시하는 토큰입니다.
반환값
비동기 메시지 전송 작업입니다.
예외
ArgumentNullException메시지가 null인 경우 발생합니다.
InvalidOperationExceptionTCP 클라이언트가 연결되지 않은 경우 발생합니다.

TcpClientTransport.cs 파일의 382 번째 라인에서 정의되었습니다.

385 {
386 ArgumentNullException.ThrowIfNull(message);
387
388 if (_client is null || State != ConnectionState.Connected)
389 {
390 throw new InvalidOperationException("TCP client is not connected.");
391 }
392
393 try
394 {
395 var stream = _client.GetStream();
396 var payload = _protocolAdapter.Encode(message);
397
398 await _frameCodec.WriteFrameAsync(stream, payload, cancellationToken)
399 .ConfigureAwait(false);
400 }
401 catch
402 {
403 SetState(ConnectionState.Faulted);
404 CleanupClient();
405
406 throw;
407 }
408 }

다음을 참조함 : _client, _frameCodec, _protocolAdapter, CleanupClient(), SetState(), State.

이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ SetState()

void Dreamine.Communication.Sockets.Clients.TcpClientTransport.SetState ( ConnectionState state)
inlineprivate

원자적 연산으로 현재 연결 상태를 설정합니다.

매개변수
state저장할 새 상태입니다.

TcpClientTransport.cs 파일의 565 번째 라인에서 정의되었습니다.

566 {
567 Interlocked.Exchange(ref _state, (int)state);
568 }

다음을 참조함 : _state.

다음에 의해서 참조됨 : ConnectAsync(), DisconnectAsync(), ReceiveLoopAsync(), SendAsync().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ ValidateOptions()

void Dreamine.Communication.Sockets.Clients.TcpClientTransport.ValidateOptions ( TcpClientTransportOptions options)
inlinestaticprivate

TCP 호스트, 포트, 버퍼 및 연결 제한 시간 설정을 검증합니다.

매개변수
options검증할 TCP 클라이언트 설정입니다.
예외
ArgumentException호스트가 비어 있는 경우 발생합니다.
ArgumentOutOfRangeException수치 설정이 허용 범위를 벗어난 경우 발생합니다.

TcpClientTransport.cs 파일의 602 번째 라인에서 정의되었습니다.

603 {
604 ArgumentException.ThrowIfNullOrWhiteSpace(options.Host);
605
606 if (options.Port <= 0 || options.Port > 65535)
607 {
608 throw new ArgumentOutOfRangeException(nameof(options.Port));
609 }
610
611 if (options.ReceiveBufferSize <= 0)
612 {
613 throw new ArgumentOutOfRangeException(nameof(options.ReceiveBufferSize));
614 }
615
616 if (options.SendBufferSize <= 0)
617 {
618 throw new ArgumentOutOfRangeException(nameof(options.SendBufferSize));
619 }
620
621 if (options.ConnectTimeoutMs <= 0)
622 {
623 throw new ArgumentOutOfRangeException(nameof(options.ConnectTimeoutMs));
624 }
625 }

다음을 참조함 : Dreamine.Communication.Sockets.Options.TcpClientTransportOptions.ConnectTimeoutMs, Dreamine.Communication.Sockets.Options.TcpClientTransportOptions.Host, Dreamine.Communication.Sockets.Options.TcpClientTransportOptions.Port, Dreamine.Communication.Sockets.Options.TcpClientTransportOptions.ReceiveBufferSize, Dreamine.Communication.Sockets.Options.TcpClientTransportOptions.SendBufferSize.

다음에 의해서 참조됨 : TcpClientTransport().

이 함수를 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ _client

TcpClient? Dreamine.Communication.Sockets.Clients.TcpClientTransport._client
private

client 값을 보관합니다.

TcpClientTransport.cs 파일의 58 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : CleanupClient(), ConnectAsync(), ReceiveLoopAsync(), SendAsync().

◆ _frameCodec

readonly IMessageFrameCodec Dreamine.Communication.Sockets.Clients.TcpClientTransport._frameCodec
private

frame Codec 값을 보관합니다.

TcpClientTransport.cs 파일의 48 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ReceiveLoopAsync(), SendAsync(), TcpClientTransport().

◆ _options

readonly TcpClientTransportOptions Dreamine.Communication.Sockets.Clients.TcpClientTransport._options
private

options 값을 보관합니다.

TcpClientTransport.cs 파일의 30 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ConnectAsync(), TcpClientTransport().

◆ _protocolAdapter

readonly IMessageProtocolAdapter Dreamine.Communication.Sockets.Clients.TcpClientTransport._protocolAdapter
private

protocol Adapter 값을 보관합니다.

TcpClientTransport.cs 파일의 39 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ReceiveLoopAsync(), SendAsync(), TcpClientTransport().

◆ _receiveLoopCts

CancellationTokenSource? Dreamine.Communication.Sockets.Clients.TcpClientTransport._receiveLoopCts
private

receive Loop Cts 값을 보관합니다.

TcpClientTransport.cs 파일의 67 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ConnectAsync(), DisconnectAsync().

◆ _receiveLoopTask

Task? Dreamine.Communication.Sockets.Clients.TcpClientTransport._receiveLoopTask
private

receive Loop Task 값을 보관합니다.

TcpClientTransport.cs 파일의 76 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ConnectAsync(), DisconnectAsync().

◆ _state

int Dreamine.Communication.Sockets.Clients.TcpClientTransport._state = (int)ConnectionState.Disconnected
private

state 값을 보관합니다.

TcpClientTransport.cs 파일의 85 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : SetState().

속성 문서화

◆ Kind

TransportKind Dreamine.Communication.Sockets.Clients.TcpClientTransport.Kind
get

TCP 전송 방식을 가져옵니다.

TcpClientTransport.cs 파일의 181 번째 라인에서 정의되었습니다.

◆ State

ConnectionState Dreamine.Communication.Sockets.Clients.TcpClientTransport.State
get

스레드 안전하게 현재 TCP 연결 상태를 가져옵니다.

TcpClientTransport.cs 파일의 171 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ConnectAsync(), DisconnectAsync(), ReceiveLoopAsync(), SendAsync().

이벤트 문서화

◆ MessageReceived

EventHandler<MessageEnvelope>? Dreamine.Communication.Sockets.Clients.TcpClientTransport.MessageReceived

완전한 TCP 프레임을 메시지로 디코딩했을 때 발생합니다.

TcpClientTransport.cs 파일의 191 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ReceiveLoopAsync().


이 클래스에 대한 문서화 페이지는 다음의 파일로부터 생성되었습니다.: