---
title: "sendData(toAllPeers:with:)"
framework: gamekit
role: symbol
role_heading: Instance Method
path: "gamekit/gksession/senddata(toallpeers:with:)"
---

# sendData(toAllPeers:with:)

Transmits a collection of bytes to all connected peers.

## Declaration

```swift
func sendData(toAllPeers data: Data!, with mode: GKSendDataMode) throws
```

## Parameters

- `data`: The bytes to be sent.
- `mode`: The mechanism used to send the data.

## Discussion

Discussion The session queues the data and transmits it when the network is free. note: In Swift, this method returns Void and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Working with Connected Peers

- [setDataReceiveHandler(_:withContext:)](gamekit/gksession/setdatareceivehandler(_:withcontext:).md)
- [send(_:toPeers:with:)](gamekit/gksession/send(_:topeers:with:).md)
- [disconnectTimeout](gamekit/gksession/disconnecttimeout.md)
- [disconnectFromAllPeers()](gamekit/gksession/disconnectfromallpeers().md)
- [disconnectPeer(fromAllPeers:)](gamekit/gksession/disconnectpeer(fromallpeers:).md)
