> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# TcpStream

`function` **TcpStream.close**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">close</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types">None</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Close the stream. A TLS stream tells its peer first. Closing twice is harmless; any other use after closing fails. A stream that is dropped closes by itself.

`function` **TcpStream.flush**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">flush</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types">None</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Send whatever is buffered. A TLS stream buffers the records it encrypts; a plain socket has nothing to flush.

`function` **TcpStream.local\_addr**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">local\_addr</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types/str">str</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

This end's address, as `"ip:port"`.

`function` **TcpStream.peer\_addr**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">peer\_addr</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types/str">str</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

The peer's address, as `"ip:port"`.

`function` **TcpStream.read**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">read</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">n</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/int">int</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types/bytes">bytes</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Read at most `n` bytes, and at most 64 KiB: whatever arrives first, at least one byte unless the peer has closed its end, where it returns `b""`. Call it again for more.

`function` **TcpStream.read\_exact**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">read\_exact</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">n</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/int">int</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types/bytes">bytes</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Read exactly `n` bytes. A peer that closes first fails it with `kind == "unexpected_eof"`.

`function` **TcpStream.read\_to\_end**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">read\_to\_end</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types/bytes">bytes</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Read until the peer closes its end.

`function` **TcpStream.read\_to\_string**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">read\_to\_string</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types/str">str</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Read until the peer closes its end, as text. Bytes that are not UTF-8 fail it with `kind == "invalid_data"`.

`function` **TcpStream.set\_nodelay**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">set\_nodelay</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">on</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/bool">bool</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types">None</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Turn Nagle's algorithm off (`True`) so small writes go out at once, or back on (`False`).

`function` **TcpStream.set\_read\_timeout**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">set\_read\_timeout</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">timeout\_ms</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/int">int</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types">None</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Fail any later read that waits longer than `timeout_ms` with `kind == "timed_out"`. `None` waits as long as the OS does.

`function` **TcpStream.set\_write\_timeout**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">set\_write\_timeout</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">timeout\_ms</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/int">int</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types">None</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Fail any later write that waits longer than `timeout_ms` with `kind == "timed_out"`. `None` waits as long as the OS does.

`function` **TcpStream.shutdown**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">shutdown</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">how</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/str">str</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types">None</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Shut down the `"read"` half, the `"write"` half, or `"both"`. After shutting down writes, the peer reads the end of the stream: the way to tell a peer that waits for it that the request is complete. A TLS stream tells its peer first, so the end is not mistaken for a cut.

`function` **TcpStream.try\_flush**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_flush</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`flush`, returning an `(err, None)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_local\_addr**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_local\_addr</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/str">str</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`local_addr`, returning an `(err, str)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_peer\_addr**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_peer\_addr</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/str">str</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`peer_addr`, returning an `(err, str)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_read**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_read</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">n</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/int">int</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/bytes">bytes</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`read`, returning an `(err, bytes)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_read\_exact**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_read\_exact</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">n</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/int">int</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/bytes">bytes</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`read_exact`, returning an `(err, bytes)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_read\_to\_end**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_read\_to\_end</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/bytes">bytes</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`read_to_end`, returning an `(err, bytes)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_read\_to\_string**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_read\_to\_string</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python"><span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/str">str</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`read_to_string`, returning an `(err, str)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_set\_nodelay**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_set\_nodelay</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">on</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/bool">bool</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`set_nodelay`, returning an `(err, None)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_set\_read\_timeout**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_set\_read\_timeout</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">timeout\_ms</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/int">int</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`set_read_timeout`, returning an `(err, None)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_set\_write\_timeout**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_set\_write\_timeout</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">timeout\_ms</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/int">int</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`set_write_timeout`, returning an `(err, None)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_shutdown**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_shutdown</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">how</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/str">str</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`shutdown`, returning an `(err, None)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_write**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_write</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">data</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/bytes">bytes</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/str">str</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/int">int</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`write`, returning an `(err, int)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.try\_write\_all**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">try\_write\_all</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">data</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/bytes">bytes</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/str">str</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <span class="meta group python"><span class="punctuation section group begin python">(</span><a href="/docs/axl/types">None</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/std">std</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io">io</a><span class="punctuation accessor dot python">.</span><a href="/docs/axl/types/std/io/error">Error</a><span class="punctuation separator tuple python">,</span> <a href="/docs/axl/types">None</a><span class="punctuation section group end python">)</span></span></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

`write_all`, returning an `(err, None)` pair instead of raising a `std.io.Error`.

`function` **TcpStream.write**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">write</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">data</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/bytes">bytes</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/str">str</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types/int">int</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Write some of `data` and return how many bytes were written, which can be fewer than `len(data)`. Use `write_all` to write all of it.

`function` **TcpStream.write\_all**

<div class="code-block mt-5 mb-8 not-prose rounded-2xl relative group text-gray-950 dark:text-gray-50 codeblock-light border border-gray-950/10 dark:border-white/10 dark:twoslash-dark bg-transparent dark:bg-transparent" numberoflines="10" language="python">
  <div class="w-0 min-w-full max-w-full py-3.5 px-4 h-full dark:bg-codeblock relative text-sm leading-6 children:!my-0 children:!shadow-none children:!bg-transparent transition-[height] duration-300 ease-in-out [&_*]:ring-0 [&_*]:outline-none [&_*]:focus:ring-0 [&_*]:focus:outline-none [&_pre>code]:pr-[3rem] [&_pre>code>span.line-highlight]:min-w-[calc(100%+3rem)] [&_pre>code>span.line-diff]:min-w-[calc(100%+3rem)] rounded-2xl bg-white overflow-x-auto scrollbar-thin scrollbar-thumb-rounded scrollbar-thumb-black/15 hover:scrollbar-thumb-black/20 active:scrollbar-thumb-black/20 dark:scrollbar-thumb-white/20 dark:hover:scrollbar-thumb-white/25 dark:active:scrollbar-thumb-white/25" data-component-part="code-block-root" tabindex="0">
    <div class="font-mono whitespace-pre leading-6">
      <pre class="shiki shiki-themes github-light-default dark-plus" language="python">
        <code language="python">
          <span class="source python"><span class="meta function python"><span class="storage type function python">def</span> <span class="entity name function python"><span class="meta generic-name python">TcpStream</span></span>.<span class="entity name function python"><span class="meta generic-name python">write\_all</span></span></span><span class="meta function parameters python"><span class="punctuation section parameters begin python">(</span></span><span class="meta function parameters python">
          <span class="variable parameter python">data</span></span><span class="meta function parameters annotation python"><span class="punctuation separator annotation parameter python">:</span> <a href="/docs/axl/types/bytes">bytes</a> <span class="keyword operator arithmetic python">|</span> <a href="/docs/axl/types/str">str</a></span><span class="meta function parameters python"><span class="punctuation separator parameters python">,</span>
          /
          <span class="punctuation section parameters end python">)</span></span><span class="meta function python"> </span><span class="meta function annotation return python"><span class="punctuation separator annotation return python">-></span> <a href="/docs/axl/types">None</a></span></span>
        </code>
      </pre>
    </div>
  </div>
</div>

Write all of `data`, a string or bytes.
