<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XPC",
  "identifier" : "/documentation/XPC/XPCSession/send(_:replyHandler:)-3wjln",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "s:3XPC10XPCSessionC4send_12replyHandleryx_ys6ResultOyAA18XPCReceivedMessageVAA12XPCRichErrorVGctKSERzlF"
  },
  "title" : "send(_:replyHandler:)"
}
-->

# send(_:replyHandler:)

Sends an encodable message over the session to the destination service, using the closure you specify to handle a reply and rich error.

```
@preconcurrency func send<Message>(_ message: Message, replyHandler: @escaping @Sendable (Result<XPCReceivedMessage, XPCRichError>) -> Void) throws where Message : Encodable
```

## Parameters

`message`

An encodable object that contains the message to send.

`replyHandler`

A closure that receives a reply, and error if one occurs, that the service sends back.

## Discussion

Sessions send messages serially in a first-in, first-out (FIFO) order. This method is safe to call from multiple dispatch queues. The session can’t indicate whether the message *delivery* is successful or not. While the session may successfully enqueue the message at the remote end of the connection, there’s no guarantee about when the destination dequeues the message and invokes the receiving session’s handler.

If the session fails to send the message, this method throws an error that contains details about the failure.

If the system tears down the session’s connection before receiving a reply, it invokes `replyHandler` with a result containing an [`XPCRichError`](/documentation/XPC/XPCRichError) describing the failure. For example, the remote service exits prematurely before sending a reply.

> Important:
> If you create an inactive session, you must activate it before sending messages. Calling this method with an inactive session crashes.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)