pub struct SctpListener(/* private fields */);
Expand description
SCTP listener which behaves like a TcpListener
.
A SCTP listener is used to wait for and accept one-to-one SCTP connections.
An accepted connection is represented by SctpStream
.
Implementations§
Source§impl SctpListener
impl SctpListener
Sourcepub fn bind<A: ToSocketAddrs>(address: A) -> Result<SctpListener>
pub fn bind<A: ToSocketAddrs>(address: A) -> Result<SctpListener>
Create a listener bound to a single address
Examples found in repository?
examples/listener.rs (line 5)
4fn main() {
5 match SctpListener::bind("0.0.0.0:3868") {
6 // match SctpListener::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
7 Ok(serv) => {
8 println!("bound to {:?}", serv.local_addrs().unwrap());
9 // serv.set_timeout(5).unwrap();
10 match serv.accept() {
11 Err(e) => println!("{:?}", e.kind()),
12 Ok((peer, _)) => {
13 println!(
14 "connection from {:?} on {:?}",
15 peer.peer_addrs().unwrap(),
16 peer.local_addrs().unwrap()
17 );
18 // Send message on stream 6
19 peer.sendmsg("foobar\n".as_bytes(), 6).unwrap();
20 let mut reply = [0u8; 1024];
21 let (len, stream) = peer.recvmsg(&mut reply).unwrap();
22 println!("Received {} bytes on stream {}", len, stream);
23 }
24 };
25 }
26 Err(e) => panic!("{:?}", e.kind()),
27 }
28}
Sourcepub fn bindx<A: ToSocketAddrs>(addresses: &[A]) -> Result<SctpListener>
pub fn bindx<A: ToSocketAddrs>(addresses: &[A]) -> Result<SctpListener>
Create a listener bound to multiple addresses. Requires at least one address
Sourcepub fn accept(&self) -> Result<(SctpStream, SocketAddr)>
pub fn accept(&self) -> Result<(SctpStream, SocketAddr)>
Accept a new connection
Examples found in repository?
examples/listener.rs (line 10)
4fn main() {
5 match SctpListener::bind("0.0.0.0:3868") {
6 // match SctpListener::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
7 Ok(serv) => {
8 println!("bound to {:?}", serv.local_addrs().unwrap());
9 // serv.set_timeout(5).unwrap();
10 match serv.accept() {
11 Err(e) => println!("{:?}", e.kind()),
12 Ok((peer, _)) => {
13 println!(
14 "connection from {:?} on {:?}",
15 peer.peer_addrs().unwrap(),
16 peer.local_addrs().unwrap()
17 );
18 // Send message on stream 6
19 peer.sendmsg("foobar\n".as_bytes(), 6).unwrap();
20 let mut reply = [0u8; 1024];
21 let (len, stream) = peer.recvmsg(&mut reply).unwrap();
22 println!("Received {} bytes on stream {}", len, stream);
23 }
24 };
25 }
26 Err(e) => panic!("{:?}", e.kind()),
27 }
28}
Sourcepub fn local_addrs(&self) -> Result<Vec<SocketAddr>>
pub fn local_addrs(&self) -> Result<Vec<SocketAddr>>
Get the listener local addresses
Examples found in repository?
examples/listener.rs (line 8)
4fn main() {
5 match SctpListener::bind("0.0.0.0:3868") {
6 // match SctpListener::bindx(&["10.0.2.15:3868", "127.0.0.1:3868"]) {
7 Ok(serv) => {
8 println!("bound to {:?}", serv.local_addrs().unwrap());
9 // serv.set_timeout(5).unwrap();
10 match serv.accept() {
11 Err(e) => println!("{:?}", e.kind()),
12 Ok((peer, _)) => {
13 println!(
14 "connection from {:?} on {:?}",
15 peer.peer_addrs().unwrap(),
16 peer.local_addrs().unwrap()
17 );
18 // Send message on stream 6
19 peer.sendmsg("foobar\n".as_bytes(), 6).unwrap();
20 let mut reply = [0u8; 1024];
21 let (len, stream) = peer.recvmsg(&mut reply).unwrap();
22 println!("Received {} bytes on stream {}", len, stream);
23 }
24 };
25 }
26 Err(e) => panic!("{:?}", e.kind()),
27 }
28}
Sourcepub fn set_timeout(&self, timeout: i32) -> Result<()>
pub fn set_timeout(&self, timeout: i32) -> Result<()>
Set timeout
in seconds on accept
Sourcepub fn try_clone(&self) -> Result<SctpListener>
pub fn try_clone(&self) -> Result<SctpListener>
Try to clone this listener
Trait Implementations§
Source§impl AsRawFd for SctpListener
impl AsRawFd for SctpListener
Source§impl FromRawFd for SctpListener
impl FromRawFd for SctpListener
Source§unsafe fn from_raw_fd(fd: RawFd) -> SctpListener
unsafe fn from_raw_fd(fd: RawFd) -> SctpListener
Constructs a new instance of
Self
from the given raw file
descriptor. Read moreAuto Trait Implementations§
impl Freeze for SctpListener
impl RefUnwindSafe for SctpListener
impl Send for SctpListener
impl Sync for SctpListener
impl Unpin for SctpListener
impl UnwindSafe for SctpListener
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more