---
title: closeWrite()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/urlsessionstreamtask/closewrite()
---

# closeWrite()

Completes any enqueued reads and writes, and then closes the write side of the underlying socket.

## Declaration

```swift
func closeWrite()
```

## Discussion

Discussion You may continue to read data using the readData(ofMinLength:maxLength:timeout:completionHandler:) method after calling this method. Any calls to write(_:timeout:completionHandler:) after calling this method will result in an error. Because the server may continue to write bytes to the client, it is recommended that you continue reading until the stream reaches end-of-file (EOF).

## See Also

### Closing read and write sockets

- [closeRead()](foundation/urlsessionstreamtask/closeread().md)
