NAME
Net::BitTorrent::Transport::TCP - TCP Transport Layer
SYNOPSIS
use Net::BitTorrent::Transport::TCP;
my $transport = Net::BitTorrent::Transport::TCP->new(
socket => $socket_handle
);
$transport->on(data => sub ( $emitter, $data ) {
$protocol->receive_data($data);
});
DESCRIPTION
Net::BitTorrent::Transport::TCP provides a standardized, non-blocking interface for handling TCP-based peer connections within the loop-agnostic Net::BitTorrent framework.
It acts as an abstraction layer between the high-level Net::BitTorrent::Peer and the physical network socket. This allows the library to handle different connection types (TCP vs uTP) using the same high-level logic. It supports pluggable filters for encryption (MSE/PE).
METHODS
new( %params )
Creates a new TCP transport object.
my $transport = Net::BitTorrent::Transport::TCP->new(
socket => $socket,
connecting => 1
);
Expected parameters:
socket-
The underlying IO::Socket (or compatible) object.
connecting- optional-
Boolean indicating if the socket is still in the process of connecting. Defaults to 1.
set_filter( $filter )
Sets a stream filter (e.g., MSE/PE).
$transport->set_filter( $mse_obj );
Expected parameters:
send_data( $data )
Sends data through the transport, applying filters if necessary.
$transport->send_data( $payload );
Expected parameters:
send_raw( $data )
Sends data directly through the transport, bypassing filters.
$transport->send_raw( $handshake );
Expected parameters:
tick( )
Processes I/O events.
$transport->tick();
This method handles connection establishment, reads incoming data, and flushes the write buffer.
receive_data( $data )
Emits a 'data' event.
$transport->receive_data( $plaintext );
Expected parameters:
close( )
Closes the socket.
$transport->close();
state( )
Returns the connection state ('CONNECTED' or 'CLOSED').
my $s = $transport->state();
socket( )
Returns the underlying socket object.
my $sock = $transport->socket();
filter( )
Returns the current filter object.
my $f = $transport->filter();
AUTHOR
Sanko Robinson <sanko@cpan.org>
COPYRIGHT
Copyright (C) 2008-2026 by Sanko Robinson.
This library is free software; you can redistribute it and/or modify it under the terms of the Artistic License 2.0.