---
title: "streamTask(with:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/urlsession/streamtask(with:)"
---

# streamTask(with:)

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

## Declaration

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

## Parameters

- `service`: A doc://com.apple.foundation/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

Return Value The new session stream task.

## Discussion

Discussion After you create the task, you must start it by calling its resume() method.

## See Also

### Adding stream tasks to a session

- [streamTask(withHostName:port:)](foundation/urlsession/streamtask(withhostname:port:).md)
- [URLSessionStreamTask](foundation/urlsessionstreamtask.md)
- [URLSessionStreamDelegate](foundation/urlsessionstreamdelegate.md)
