Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of NSAPITests by
Revision 11:fbfe3498404a, committed 2016-05-10
- Comitter:
- c1728p9
- Date:
- Tue May 10 21:38:38 2016 -0500
- Parent:
- 10:0d938ec9100c
- Child:
- 12:152ae238ddc1
- Commit message:
- Add support for IPv6
Changed in this revision
| EchoServer.py | Show annotated file Show diff for this revision Revisions of this file |
--- a/EchoServer.py Thu Apr 21 01:54:51 2016 -0500
+++ b/EchoServer.py Tue May 10 21:38:38 2016 -0500
@@ -18,8 +18,19 @@
tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
tcp.listen(5)
+ udp6 = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
+ udp6.bind(('', port))
+ udp6.setblocking(0)
+ udp6.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+
+ tcp6 = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+ tcp6.bind(('', port))
+ tcp6.setblocking(0)
+ tcp6.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ tcp6.listen(5)
+
print "running on port %d" % port
- sockets = [tcp, udp]
+ sockets = [tcp, udp, tcp6, udp6]
clients = []
while True:
@@ -42,6 +53,23 @@
except socket.error:
pass
+ try:
+ data, addr = udp6.recvfrom(1 << 12)
+ print 'udp6 %s:%d %d' % (addr[0], addr[1], len(data))
+ udp6.sendto(data, addr)
+ except socket.error:
+ pass
+
+ try:
+ client, addr = tcp6.accept()
+ print 'tcp6 %s:%d connect' % (addr[0], addr[1])
+ client.setblocking(0)
+ client.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ sockets.append(client)
+ clients.append((client, addr))
+ except socket.error:
+ pass
+
for client, addr in clients:
try:
data = client.recv(1 << 12)
