File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 8
8
9
9
C < IO::Socket::INET > provides TCP sockets, both the server and the client side.
10
10
11
- = comment TODO: examples of both client and server
11
+ Here is an example of a very simplistic "echo" server that listens on
12
+ localhost, port 3333:
13
+
14
+ = begin code
15
+ use v6;
16
+
17
+ my $listen = IO::Socket::INET.new(:listen, :localport(3333));
18
+ loop {
19
+ my $conn = $listen.accept;
20
+ while my $buf = $conn.recv(:bin) {
21
+ $conn.write: $buf;
22
+ }
23
+ $conn.close;
24
+ }
25
+ = end code
26
+
27
+ And a client that connects to it, and prints out what the server answers:
28
+
29
+ = begin code
30
+ use v6;
31
+
32
+ my $conn = IO::Socket::INET.new(:host<localhost>, :port(3333));
33
+ $conn.send: 'Hello, Perl 6';
34
+ say $conn.recv;
35
+ $conn.close;
36
+ = end code
12
37
13
38
= head1 Methods
14
39
You can’t perform that action at this time.
0 commit comments