Skip to content

Commit 657043a

Browse files
committed
keep send side open while receiving in tcp-p3 example
Netcat likes to close the connection if the receive half is closed by the remote host, regardless of whether stdin has been closed, and there's no obvious way to change that behavior. So on the client side we hold both halves open until we've received something, which matches the p2 example behavior.
1 parent 6a20a40 commit 657043a

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

examples/tcp-p3/app.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,12 @@ async def send_and_receive(address: IPAddress, port: int) -> None:
6969

7070
send_tx, send_rx = wit_world.byte_stream()
7171
async def write() -> None:
72-
with send_tx:
73-
await send_tx.write_all(b"hello, world!")
74-
await asyncio.gather(sock.send(send_rx), write())
72+
await send_tx.write_all(b"hello, world!")
7573

7674
recv_rx, recv_fut = sock.receive()
7775
async def read() -> None:
7876
with recv_rx:
7977
data = await recv_rx.read(1024)
8078
print(f"received: {str(data)}")
81-
await asyncio.gather(recv_fut.read(), read())
79+
send_tx.__exit__(None, None, None)
80+
await asyncio.gather(recv_fut.read(), read(), sock.send(send_rx).read(), write())

0 commit comments

Comments
 (0)