Skip to main content

SrtSocketBuilder

Struct SrtSocketBuilder 

Source
pub struct SrtSocketBuilder { /* private fields */ }
Expand description

Struct to build sockets.

This is the typical way to create instances of SrtSocket, which implements both Sink + Stream, as they can be both receivers and senders.

You need to decided on a ConnInitMethod in order to create a SrtSocketBuilder. See that documentation for more details.

§Examples:

Simple:

let (a, b) = futures::try_join!(
    SrtSocketBuilder::new_listen().local_port(3333).connect(),
    SrtSocketBuilder::new_connect("127.0.0.1:3333").connect(),
)?;

Rendezvous example:

let (a, b) = futures::try_join!(
    SrtSocketBuilder::new_rendezvous("127.0.0.1:4444").local_port(5555).connect(),
    SrtSocketBuilder::new_rendezvous("127.0.0.1:5555").local_port(4444).connect(),
)?;

§Panics:

  • There is no tokio runtime

Implementations§

Source§

impl SrtSocketBuilder

Source

pub fn new(conn_type: ConnInitMethod) -> Self

Defaults to binding to 0.0.0.0:0 (all adaptors, OS assigned port), 50ms latency, and no encryption. Generally easier to use new_listen, new_connect or new_rendezvous

Source

pub fn new_listen() -> Self

Source

pub fn new_connect(to: impl ToSocketAddrs) -> Self

Connects to the first address yielded by to

§Panics
Source

pub fn new_rendezvous(to: impl ToSocketAddrs) -> Self

Connects to the first address yielded by to

§Panics
Source

pub fn conn_type(&self) -> &ConnInitMethod

Gets the ConnInitMethod of the builder.

let builder = SrtSocketBuilder::new(ConnInitMethod::Listen);
assert_eq!(builder.conn_type(), &ConnInitMethod::Listen);
Source

pub fn local_addr(self, local_addr: IpAddr) -> Self

Sets the local address of the socket. This can be used to bind to just a specific network adapter instead of the default of all adapters.

Source

pub fn local_port(self, port: u16) -> Self

Sets the port to bind to. In general, to be used for ConnInitMethod::Listen and ConnInitMethod::Rendezvous, but generally not ConnInitMethod::Connect.

Source

pub fn latency(self, latency: Duration) -> Self

Set the latency of the connection. The more latency, the more time SRT has to recover lost packets.

Source

pub fn crypto(self, size: u8, passphrase: String) -> Self

Se the crypto paramters. However, this is currently unimplemented.

§Panics:
  • size is not 16, 24, or 32.
Source

pub async fn connect_with_sock<T>(self, socket: T) -> Result<SrtSocket, Error>
where T: Stream<Item = Result<(Packet, SocketAddr), PacketParseError>> + Sink<(Packet, SocketAddr), Error = Error> + Unpin + Send + 'static,

Connect with a custom socket. Not typically used, see connect instead.

Source

pub async fn connect(self) -> Result<SrtSocket, Error>

Connects to the remote socket. Resolves when it has been connected successfully.

Source

pub async fn build_multiplexed( self, ) -> Result<impl Stream<Item = Result<(Connection, PackChan), Error>>, Error>

Build a multiplexed connection. This acts as a sort of server, allowing many connections to this one socket.

§Panics:

If this is built with a non-listen builder

Trait Implementations§

Source§

impl Clone for SrtSocketBuilder

Source§

fn clone(&self) -> SrtSocketBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SrtSocketBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V