diff --git a/example/dotcp.rs b/example/dotcp.rs index e69de29b..1ce8d0c0 100644 --- a/example/dotcp.rs +++ b/example/dotcp.rs @@ -0,0 +1,36 @@ + +use std::net::{IpAddr, Ipv4Addr}; +use std::time::Duration; +use tokio::runtime::Runtime; +use crate::client::tcp_connection::ClientTCPConnection; +use crate::message::DnsMessage; +use crate::client::client_error::ClientError; + +fn main() -> Result<(), ClientError> { + let rt = Runtime::new().unwrap(); + + + let server_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)); + + let timeout = Duration::from_secs(5); + + + let tcp_connection = ClientTCPConnection::new(server_ip, timeout); + + + let dns_query = DnsMessage::new_query("example.com", crate::message::rrtype::Rrtype::A); + + + rt.block_on(async { + match tcp_connection.send(dns_query).await { + Ok(response) => { + println!("Respuesta recibida: {:?}", response); + } + Err(e) => { + eprintln!("Error al enviar la consulta DNS: {:?}", e); + } + } + }); + + Ok(()) +} \ No newline at end of file diff --git a/example/dotls.rs b/example/dotls.rs index e69de29b..69c1621b 100644 --- a/example/dotls.rs +++ b/example/dotls.rs @@ -0,0 +1,32 @@ +use std::net::{IpAddr, Ipv4Addr}; +use std::time::Duration; +use tokio::runtime::Runtime; +use crate::client::tls_connection::ClientTLSConnection; +use crate::message::DnsMessage; +use crate::client::client_error::ClientError; + +fn main() -> Result<(), ClientError> { + let rt = Runtime::new().unwrap(); + + let server_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)); + + let timeout = Duration::from_secs(5); + + let tls_connection = ClientTLSConnection::new(server_ip, timeout); + + let dns_query = DnsMessage::new_query("example.com", crate::message::rrtype::Rrtype::A); + + // Ejecutar la tarea asincrónica en el Runtime + rt.block_on(async { + match tls_connection.send(dns_query).await { + Ok(response) => { + println!("Respuesta recibida: {:?}", response); + } + Err(e) => { + eprintln!("Error al enviar la consulta DNS: {:?}", e); + } + } + }); + + Ok(()) +} \ No newline at end of file diff --git a/example/doudp.rs b/example/doudp.rs index e69de29b..14aee618 100644 --- a/example/doudp.rs +++ b/example/doudp.rs @@ -0,0 +1,36 @@ +use std::net::{IpAddr, Ipv4Addr}; +use std::time::Duration; +use tokio::runtime::Runtime; +use crate::client::udp_connection::ClientUDPConnection; +use crate::message::DnsMessage; +use crate::client::client_error::ClientError; + +fn main() -> Result<(), ClientError> { + // Crear una instancia de Runtime para ejecutar tareas asincrónicas + let rt = Runtime::new().unwrap(); + + // Dirección IP del servidor DNS + let server_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 0, 1)); + // Tiempo de espera para la conexión + let timeout = Duration::from_secs(5); + + // Crear una instancia de ClientUDPConnection + let udp_connection = ClientUDPConnection::new(server_ip, timeout); + + // Crear una consulta DNS (esto es solo un ejemplo, ajusta según tu implementación) + let dns_query = DnsMessage::new_query("example.com", crate::message::rrtype::Rrtype::A); + + // Ejecutar la tarea asincrónica en el Runtime + rt.block_on(async { + match udp_connection.send(dns_query).await { + Ok(response) => { + println!("Respuesta recibida: {:?}", response); + } + Err(e) => { + eprintln!("Error al enviar la consulta DNS: {:?}", e); + } + } + }); + + Ok(()) +} \ No newline at end of file