trellis-net

Crates.iotrellis-net
lib.rstrellis-net
version0.1.0
sourcesrc
created_at2023-01-06 17:09:29.832581
updated_at2023-01-06 17:09:29.832581
descriptionA simple networking library for Rust.
homepagehttps://github.com/ShardulNalegave/trellis
repositoryhttps://github.com/ShardulNalegave/trellis
max_upload_size
id752427
size13,506
Shardul Nalegave (ShardulNalegave)

documentation

README

Trellis

A simple networking library for Rust-Lang.


Getting Started

Listener:-


// ===== Imports =====
use std::io::Error;
use trellis::prelude::*;
// ===================

#[tokio::main]
async fn main() -> Result<(), Error> {
  let address = Address::new(
    (127, 0, 0, 1),
    8080,
  );
  
  let listener = Listener::new(address).await?;
  println!("Listening at: {:?}", listener.local_addr);
  loop {
    let mut conn = listener.accept().await?;
    println!("New Connection: {:?}", conn.peer_addr);
    conn.write_u8(100).await?;
    conn.write_string(String::from("Hello, World!")).await?;
  }
  Ok(())
}

Client:-


// ===== Imports =====
use std::io::Error;
use trellis::prelude::*;
// ===================

#[tokio::main]
async fn main() -> Result<(), Error> {
  let address = Address::new(
    (127, 0, 0, 1),
    8080,
  );
  
  let mut conn = Connection::new(address).await?;
  println!("Connected to: {:?}", conn.peer_addr);
  println!("Local Address: {:?}", conn.local_addr);
  let num = conn.read_u8().await?;
  println!("Message Received: {:?}", num);
  let data = conn.read_string(13).await?;
  println!("{:?}", data);
  Ok(())
}

Commit count: 17

cargo fmt