<!--
{
  "availability" : [
    "iOS: 9.0.0 - 27.0.0",
    "iPadOS: 9.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "macOS: 10.11.0 - 27.0.0",
    "tvOS: 9.0.0 - 27.0.0",
    "visionOS: 1.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URLSession/streamTask(with:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLSession(im)streamTaskWithNetService:"
  },
  "title" : "streamTask(with:)"
}
-->

# streamTask(with:)

Creates a task that establishes a bidirectional TCP/IP connection using a specified network service.

```
func streamTask(with service: NetService) -> URLSessionStreamTask
```

## Parameters

`service`

A [`NetService`](/documentation/Foundation/NetService) object used to determine the endpoint of the TCP/IP connection. This network service is resolved before any data is read or written to the resulting stream task.

## Return Value

The new session stream task.

## Discussion

After you create the task, you must start it by calling its [`resume()`](/documentation/Foundation/URLSessionTask/resume()) method.

---

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)