Contents

send(content:contentContext:isComplete:completion:)

Sends data on a connection using a custom Data type.

Declaration

@preconcurrency final func send<Content>(content: Content?, contentContext: NWConnection.ContentContext = .defaultMessage, isComplete: Bool = true, completion: NWConnection.SendCompletion) where Content : DataProtocol

Parameters

  • content:

    The data to send on the connection. May be nil if this send marks its context as complete, such as by sending Finalmessage as the context and marking the send complete to send a write-close.

  • contentContext:

    The context associated with the content, which represents a logical message to be sent on the connection. All content sent within a single context will be sent as an in-order unit, up until the point that the context is marked complete. Once a context is marked complete, it may be re-used as a new logical message. Protocols like TCP that cannot send multiple independent messages at once (serial bytestreams) will only start processing a new context once the prior context has been marked complete. Defaults to Defaultmessage.

  • isComplete:

    A flag indicating if the caller’s sending context (logical message) is now complete. Until a context is marked complete, content sent for other contexts may not be sent immediately (if the protocol requires sending bytes serially, like TCP). For datagram protocols, like UDP, this flag indicates that the content represents a complete datagram.

    When sending using streaming protocols like TCP, this flag can be used to mark the end of a single message on the stream, of which there may be many. However, it can also indicate that the connection should send a “write close” (a TCP FIN) if the sending context is the final context on the connection. Specifically, to send a “write close”, pass Finalmessage or Defaultstream for the context (or create a custom context and set Isfinal), and mark the send as complete.

  • completion:

    A completion handler (Contentprocessed(_:)) to notify the caller when content has been processed by the connection, or a marker that this data is idempotent (Idempotent) and may be sent multiple times as fast open data if Allowfastopen is set.

See Also

Sending and Receiving Data