Skip to content

raku-community-modules/IO-Socket-SSL

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Actions Status Actions Status Actions Status

NAME

IO::Socket::SSL - interface for SSL connection

SYNOPSIS

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;
}

DESCRIPTION

This module provides an interface for SSL connections.

It uses C to setting up the connection so far (hope it will change soon).

METHODS

method new

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

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

method print(IO::Socket::SSL:, Str $s)

method send

DEPRECATED. Use .print instead

method send(IO::Socket::SSL:, Str $s)

Sends $s to the other side (server/client).

method accept

method accept(IO::Socket::SSL:);

Waits for a new incoming connection and accepts it.

close

method close(IO::Socket::SSL:)

Closes the connection.

SEE ALSO

OpenSSL

EXAMPLE

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;

AUTHOR

  • Filip Sergot

Source can be located at: https://github.com/raku-community-modules/IO-Socket-SSL . Comments and Pull Requests are welcome.

COPYRIGHT AND LICENSE

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.