Skip to content

Commit

Permalink
IPv6 version of TCP programs (#32)
Browse files Browse the repository at this point in the history
* IPv6 version of TCP programs

---------

Co-authored-by: Stephane Bortzmeyer <[email protected]>
  • Loading branch information
bortzmeyer and Stephane Bortzmeyer authored Jan 4, 2024
1 parent 2528c77 commit a699cc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions book-src/04-01-tcp-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,12 @@ When start starts up, try test like this:
echo "hello zig" | nc localhost <port>
```

By default, the program listens with IPv4. If you want IPv6, use `::1`
instead of `127.0.0.1`, replace `net.Ip4Address.parse` by
`net.Ip6Address.parse` and the field `.in` in the creation of the
`net.Address` with `.in6`.

(And connect to something like `ip6-localhost`, depending on the way
your machine is set up.)

The next section will show how to connect this server using Zig code.
5 changes: 5 additions & 0 deletions book-src/04-02-tcp-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ You can run it using `zig build run-04-02 -- <port>`.
```zig
{{#include ../src/04-02.zig }}
```

By default, the program connects with IPv4. If you want IPv6, use
`::1` instead of `127.0.0.1`, replace `net.Address.parseIp4` by
`net.Address.parseIp6`.

0 comments on commit a699cc9

Please sign in to comment.