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
impl SrtSocketBuilder
Sourcepub fn new(conn_type: ConnInitMethod) -> Self
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
pub fn new_listen() -> Self
Sourcepub fn new_connect(to: impl ToSocketAddrs) -> Self
pub fn new_connect(to: impl ToSocketAddrs) -> Self
Sourcepub fn new_rendezvous(to: impl ToSocketAddrs) -> Self
pub fn new_rendezvous(to: impl ToSocketAddrs) -> Self
Sourcepub fn conn_type(&self) -> &ConnInitMethod
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);Sourcepub fn local_addr(self, local_addr: IpAddr) -> Self
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.
Sourcepub fn local_port(self, port: u16) -> Self
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.
Sourcepub fn latency(self, latency: Duration) -> Self
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.
Sourcepub fn crypto(self, size: u8, passphrase: String) -> Self
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.
Sourcepub 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,
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.
Sourcepub async fn connect(self) -> Result<SrtSocket, Error>
pub async fn connect(self) -> Result<SrtSocket, Error>
Connects to the remote socket. Resolves when it has been connected successfully.
Sourcepub async fn build_multiplexed(
self,
) -> Result<impl Stream<Item = Result<(Connection, PackChan), Error>>, Error>
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
impl Clone for SrtSocketBuilder
Source§fn clone(&self) -> SrtSocketBuilder
fn clone(&self) -> SrtSocketBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more