/// <summary> /// Sends a message asynchronously. /// </summary> /// <typeparam name="TMessage">The message type.</typeparam> /// <param name="message">The message.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <exception cref="NetworkConnectorIsNotYetStartedException">If <see cref="IsRunning"/> is <c>false</c>.</exception> /// <returns>Returns a <see cref="Task"/> to await.</returns> public async Task SendMessageAsync <TMessage>(TMessage message, CancellationToken cancellationToken) { if (!IsRunning) { throw new NetworkConnectorIsNotYetStartedException("NetworkConnector has not started yet. Call Start() first"); } Message constructedMessage = _messageConstructor.ConstructMessage(message); await SendPacketAsync(constructedMessage.Header, cancellationToken); await SendPacketAsync(constructedMessage.Body, cancellationToken); }