Skip to content

Commit 67bc4c3

Browse files
gfldexzoffixznet
authored andcommitted
Better example for IO::Socket::Async, closes #1546 (#1547)
* Better example, closes #1546 * Update Async.pod6 * Update Async.pod6
1 parent 3702cc2 commit 67bc4c3

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

doc/Type/IO/Socket/Async.pod6

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,29 @@
99
C<IO::Socket::Async> provides asynchronous TCP sockets, for both the
1010
server and the client side.
1111
12-
Here is the equivalent example to that in L<IO::Socket::INET> of a simple
13-
echo server that listens on port 3333:
14-
15-
=begin code
16-
use v6.c;
12+
Here is a simple example of a simple "hello world"
13+
http server that listens on port 3333:
1714
15+
=begin code :skip-test<IO>
1816
react {
19-
whenever IO::Socket::Async.listen('localhost', 3333) -> $conn {
20-
whenever $conn.Supply(:bin) -> $buf {
21-
await $conn.write: $buf
17+
whenever IO::Socket::Async.listen('0.0.0.0', 8080) -> $conn {
18+
whenever $conn.Supply.lines {
19+
say .Str;
20+
21+
{ try $conn.print(.Str ~ "\n") } for
22+
"HTTP/1.1 200 OK",
23+
"Content-Type: text/html; charset=UTF-8",
24+
"Content-Encoding: UTF-8",
25+
"",
26+
"<html><body>Hello World!</body></html>";
27+
28+
$conn.close;
29+
}
30+
CLOSE {
31+
note „{now} connection closed“;
2232
}
2333
}
34+
CATCH { default { say .^name, ': ', .Str; say "handled in $?LINE"; } }
2435
}
2536
=end code
2637

0 commit comments

Comments
 (0)