File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change 9
9
C < IO::Socket::Async > provides asynchronous TCP sockets, for both the
10
10
server and the client side.
11
11
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:
17
14
15
+ = begin code :skip-test<IO>
18
16
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“;
22
32
}
23
33
}
34
+ CATCH { default { say .^name, ': ', .Str; say "handled in $?LINE"; } }
24
35
}
25
36
= end code
26
37
You can’t perform that action at this time.
0 commit comments