[][src]Function koibumi_socks::connect

pub async fn connect<'_, S>(
    server: &'_ mut S,
    destination: SocketAddr
) -> Result<SocketAddr> where
    S: ReadExt + WriteExt + Unpin

Connects to an arbitrary network destination via a SOCKS5 server.

The SOCKS5 server is specified by a TCP socket which is already connected to the SOCKS5 server.

Examples

Connect to the web server at example.net:80 via a local Tor SOCKS5 proxy at 127.0.0.1:9050, issue a GET command, read and print the response:

use async_std::{
    io::{prelude::WriteExt, ReadExt},
    net::TcpStream,
};
use koibumi_socks::{self as socks, DomainName, SocketDomainName};

let mut stream = TcpStream::connect("127.0.0.1:9050").await?;

let destination = socks::SocketAddr::DomainName(
    SocketDomainName::new(
        DomainName::new(b"example.net".to_vec()).unwrap(), 80));

let _dest = socks::connect(&mut stream, destination).await?;

stream.write_all(b"GET /\n").await?;

let mut bytes = Vec::new();
stream.read_to_end(&mut bytes).await?;
print!("{}", String::from_utf8_lossy(&bytes));