This example sends four messages called data portions to the example.com
website using a single system call on an orginary TcpStream
:
(examples/sender.rs
)
```rust
use sendmmsg::Sendmmsg; use std::io::IoVec; use std::net::TcpStream;
fn main() { // Specify all the messages you want to send let messages = &mut [ (0, IoVec::new(b"Generals gathered in their masses")), (0, IoVec::new(b"Just like witches at black masses")), (0, IoVec::new(b"Evil minds that plot destruction")), (0, IoVec::new(b"Sorcerers of death's construction")), ];
// Setup the `TcpStream` instance connected to example.com
let socket = TcpStream::connect("93.184.216.34:80").unwrap();
// Finally, send all the messages above
match socket.sendmmsg(messages) {
Err(error) => eprintln!("An error occurred: {}!", error),
Ok(packets) => println!("Packets sent: {}", packets),
}
} ```
More realistic examples are located in the examples
directory (and you are able to run them). To investigate the library abstractions, visit the official documentation.
You are always welcome for any contribution to this project! But before you start, you should read the appropriate document to know about the preferred development process and the basic communication rules.
Temirkhan Myrzamadi <gymmasssorla@gmail.com> (the author)