v0l / socks5

SOCKS5 implemented in dart
GNU General Public License v3.0
4 stars 2 forks source link
dart flutter socks socks5

socks

A SOCKS5 connection handler

Example

/// [SOCKSSocket] uses a raw socket to authorize 
/// and request a connection, connect to your socks proxy server
final sock = await RawSocket.connect(InternetAddress.loopbackIPv4, 9050);

/// pass the socket to [SOCKSSocket]
final proxy = SOCKSSocket(sock);

/// request the proxy to connect to a host
/// this call will throw exceptions if connection attempt fails from the proxy
await proxy.connect("google.com:80");

/// Now you can use the [sock] from earlier, since we can only listen
/// once on a [RawSocket] we must set the [onData] function to intercept 
/// the events from the socket
proxy.subscription.onData((RawSocketEvent event) {
    /// [RawSocketEvent] messages are here
    /// read from here.. 
    if (event == RawSocketEvent.read) {
      final data = sock.read(sock.available());
      ...
    }
});

/// To connect with an [InternetAddress] use:
/// await s.connectIp(InternetAddress.loopbackIPv4, 80);

/// keepOpen=false will call close the [RawSocket]
await proxy.close(keepOpen: false);