Discussion:
posix: Add server example for IPv6, because it was not obvious to me
Arne Babenhauserheide
2018-11-10 00:51:10 UTC
Permalink
From 0ce11db4c224a99ef70835ee63792321eac038d6 Mon Sep 17 00:00:00 2001
From: Arne Babenhauserheide <***@draketo.de>
Date: Sat, 10 Nov 2018 01:44:47 +0100
Subject: [PATCH] posix: Add server example for IPv6, because it was not
obvious to me

---
doc/ref/posix.texi | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)

diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi
index 5cb68a292..674598d90 100644
--- a/doc/ref/posix.texi
+++ b/doc/ref/posix.texi
@@ -3504,6 +3504,29 @@ client.
(close client))))
@end example

+@cindex socket server example ipv6
+The following example uses an IPv6 socket listening on all addresses
+@example
+(let ((s (socket PF_INET6 SOCK_STREAM 0)))
+ (setsockopt s SOL_SOCKET SO_REUSEADDR 1)
+ (bind s AF_INET6 (inet-pton AF_INET6 "::") 2904)
+ (listen s 5)
+
+ (simple-format #t "Listening for clients in pid: ~S" (getpid))
+ (newline)
+
+ (while #t
+ (let* ((client-connection (accept s))
+ (client-details (cdr client-connection))
+ (client (car client-connection)))
+ (simple-format #t "Got new client connection: ~S"
+ client-details)
+ (newline)
+ ;; @r{Send back the greeting to the client port}
+ (display "Hello client\r\n" client)
+ (close client))))
+@end example
+

@node System Identification
@subsection System Identification
--
2.19.1
Loading...