mirror of
https://github.com/YGGverse/agate.git
synced 2026-04-08 20:45:29 +00:00
Working echo server
This commit is contained in:
parent
bf439b4c52
commit
a0c20258cb
3 changed files with 105 additions and 5 deletions
15
src/main.rs
15
src/main.rs
|
|
@ -19,14 +19,19 @@ use {
|
|||
pub type Result<T=()> = std::result::Result<T, Box<dyn Error>>;
|
||||
|
||||
async fn connection(acceptor: TlsAcceptor, stream: TcpStream) -> io::Result<()> {
|
||||
let mut stream = acceptor.accept(stream).await?;
|
||||
let mut body = Vec::new();
|
||||
stream.read_to_end(&mut body).await?;
|
||||
stream.write_all(&body).await?;
|
||||
let stream = acceptor.accept(stream).await?;
|
||||
let mut stream = async_std::io::BufReader::new(stream);
|
||||
let mut body = String::new();
|
||||
stream.read_line(&mut body).await?;
|
||||
let mut stream = stream.into_inner();
|
||||
stream.write_all(b"20 text/plain\r\n").await?;
|
||||
stream.write_all(body.as_bytes()).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result {
|
||||
env_logger::init();
|
||||
|
||||
let certs = certs(&mut BufReader::new(File::open("tests/cert.pem")?))
|
||||
.expect("Error reading certificate file");
|
||||
let mut keys = rsa_private_keys(&mut BufReader::new(File::open("tests/key.rsa")?))
|
||||
|
|
@ -36,7 +41,7 @@ fn main() -> Result {
|
|||
config.set_single_cert(certs, keys.remove(0))?;
|
||||
let acceptor = TlsAcceptor::from(Arc::new(config));
|
||||
|
||||
let addr = "127.0.0.1:1965";
|
||||
let addr = "localhost:1965";
|
||||
|
||||
task::block_on(async {
|
||||
let listener = TcpListener::bind(addr).await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue