Expand description
src/lib.rs
§Welcome
Btp is stands for ‘Blog Transfer Protocol’ which developed while developing this project. The protocol has a basic structure, a ‘header’ which consists of 10 bytes, and the rest of the message, which can be reach 4GiB.
This protocol handles a basic transmission task between server and client. To add this project to repository
cargo add btpor with TLS,
cargo add btp --features tlsAfter you added the library to project, It will be accessible under the crate name btp.
§Examples
Let me teach the structure with examples here;
§NO TLS
Examples below will not use any safe transmission with TLS encryption, but bare and crystal clear transmission.
§Basic client example without TSL;
use btp::message::BtpMessage;
use btp::socket::{BtpConfig, BtpSocket};
#[tokio::main]
async fn main() {
let address = "127.0.0.1:8080".parse().unwrap();
// First we created a basic client config, includes our server address,
// and the VERSION of the btp protocol used.
let client_conf = BtpConfig::from_addr(address);
// Connected to given address using conf, and awaited since it's an async connection.
let mut client_socket = BtpSocket::connect(client_conf).await.unwrap();
// Created a message as [&str] and converted it into request.
let body: &str = "Hello, BTP!";
let msg = BtpMessage::from_str(body);
// End sended to client (I guess)
client_socket.write_message(msg).await.unwrap();
}§Basic server example without TSL;
use btp::message::BtpMessage;
use btp::socket::{BtpConfig, BtpSocket};
#[tokio::main]
async fn main() {
let address = "127.0.0.1:8080".parse().unwrap();
// First we created a basic client config, includes our server address,
// and the VERSION of the btp protocol used.
let client_conf = BtpConfig::from_addr(address);
// Connected to given address using conf, and awaited since it's an async connection.
let mut client_socket = BtpSocket::connect(client_conf).await.unwrap();
// Created a message as [&str] and converted it into request.
let body: &str = "Hello, BTP!";
let msg = BtpMessage::from_str(body);
// End sended to client (I guess)
client_socket.write_message(msg).await.unwrap();
}Modules§
Constants§
- VERSION
- Actual current version of the protocol. Used in
socket::BtpConfig