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

# streamTask(withHostName:port:)

Creates a task that establishes a bidirectional TCP/IP connection to a specified hostname and port.

## Declaration

```swift
func streamTask(withHostName hostname: String, port: Int) -> URLSessionStreamTask
```

## Parameters

- `hostname`: The hostname of the connection endpoint.
- `port`: The port of the connection endpoint.

## 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(with:)](foundation/urlsession/streamtask(with:).md)
- [URLSessionStreamTask](foundation/urlsessionstreamtask.md)
- [URLSessionStreamDelegate](foundation/urlsessionstreamdelegate.md)
