DEV Community

Yuki Kimoto
Yuki Kimoto

Posted on

SPVM::IO::Socket::INET is available in experimental status.

SPVM::IO::Socket::INET is available in the experimental status.

  use IO::Socket::INET;

  my $host = "google.com";
  my $port = 80;
  my $io_socket = IO::Socket::INET->new({
    PeerAddr => $host,
    PeerPort => $port
  });

  my $send_buffer = "GET / HTTP/1.0\r\n\r\n";
  $socket->send($send_buffer);

  my $recv_buffer = (mutable string)new_string_len 100;
  while (1) {
    my $recv_length = $socket->recv($recv_buffer);

    if ($recv_length < 0) {
      die "Read error";
    }

    say Fn->substr($recv_buffer, 0, $recv_length);

    if ($recv_length < length $recv_buffer) {
      last;
    }
  }
Enter fullscreen mode Exit fullscreen mode

This module is a IO::Socket::INET porting to SPVM.

SPVM is approaching the goal of IoT. SPVM can access the Web via HTTP and create an executable file using spvmcc for devices.

Top comments (0)