IO::Socket::SSL - interface for SSL connection
use IO::Socket::SSL;
my $ssl = IO::Socket::SSL.new(:host<example.com>, :port(443));
if $ssl.print("GET / HTTP/1.1\r\n\r\n") {
say $ssl.recv;
}
This module provides an interface for SSL connections.
It uses C to setting up the connection so far (hope it will change soon).
method new(*%params) returns IO::Socket::SSL
Gets params like:
-
encoding : connection's encoding
-
input-line-separator : specifies how lines of input are separated
for client state:
-
host : host to connect
-
port : port to connect
for server state:
-
localhost : host to use for the server
-
localport : port for the server
-
listen : create a server and listen for a new incoming connection
-
certfile : path to a file with certificates
method recv(IO::Socket::SSL:, Int $n = 1048576, Bool :$bin = False)
Reads $n bytes from the other side (server/client).
Bool :$bin if we want it to return Buf instead of Str.
method print(IO::Socket::SSL:, Str $s)
DEPRECATED. Use .print
instead
method send(IO::Socket::SSL:, Str $s)
Sends $s to the other side (server/client).
method accept(IO::Socket::SSL:);
Waits for a new incoming connection and accepts it.
method close(IO::Socket::SSL:)
Closes the connection.
To download sourcecode of e.g. github.com:
use IO::Socket::SSL;
my $ssl = IO::Socket::SSL.new(:host<github.com>, :port(443));
my $content = Buf.new;
$ssl.print("GET /\r\n\r\n");
while my $read = $ssl.recv {
$content ~= $read;
}
say $content;
- Filip Sergot
Source can be located at: https://github.com/raku-community-modules/IO-Socket-SSL . Comments and Pull Requests are welcome.
Copyright 2014 - 2022 Filip Sergot
Copyright 2023 - 2025 The Raku Community
This library is free software; you can redistribute it and/or modify it under the MIT License.