---
title: "urlSession(_:betterRouteDiscoveredFor:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlsessionstreamdelegate/urlsession(_:betterroutediscoveredfor:)"
---

# urlSession(_:betterRouteDiscoveredFor:)

Tells the delegate that a better route to the host has been detected for the stream.

## Declaration

```swift
optional func urlSession(_ session: URLSession, betterRouteDiscoveredFor streamTask: URLSessionStreamTask)
```

## Parameters

- `session`: The session of the stream task that discovered a better route.
- `streamTask`: The stream task that discovered a better route.

## Discussion

Discussion This method is called when the URL loading system determines that a better route to the endpoint host is available. For example, this method may be called when a Wi-Fi interface becomes available. You should consider completing pending work and creating a new stream task in order to take advantage of better routes when they become available.
