Skip to content

Commit aaac2fe

Browse files
author
Artiom N.
committed
Chapter 2 dualstack examples were rewritten to UDP
1 parent d427ae7 commit aaac2fe

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/book01/ch02/python/dualstack-server.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22

33
import socket
44

5-
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM, socket.IPPROTO_TCP) as sock:
5+
with socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP) as sock:
66
sock.bind(('::', 12345, 0, 0))
7-
sock.listen()
7+
88
print(f'Listening socket = {sock}, ' f'dual stack = {socket.has_dualstack_ipv6()}\n')
99

1010
while True:
11-
s, addr = sock.accept()
12-
print(f'Client socket = {s}\nClient address = {addr}')
13-
14-
with s:
15-
while data := s.recv(15):
16-
print(data)
11+
while data := sock.recvfrom(15):
12+
print(data)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python3
2+
3+
import socket
4+
5+
6+
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
7+
sock.sendto(b'test ipv6', ('::', 12345))
8+
sock.close()
9+
10+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
11+
sock.sendto(b'test ipv4', ('127.0.01', 12345))
12+
sock.close()

src/book01/ch02/python/ipv6-client.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)