SOCKSSocket class

A SOCKS5 socket.

This class is a wrapper around the Socket class that implements the SOCKS5 protocol. It supports SSL and non-SSL connections.

Properties:

  • proxyHost: The host of the SOCKS5 proxy server.
  • proxyPort: The port of the SOCKS5 proxy server.
  • _socksSocket: The underlying Socket that connects to the SOCKS5 proxy server.
  • _responseController: A StreamController that listens to the _socksSocket and broadcasts the response.

Methods:

  • connect: Connects to the SOCKS5 proxy server.
  • connectTo: Connects to the specified domain and port through the SOCKS5 proxy server.
  • write: Converts object to a String by invoking Object.toString and sends the encoding of the result to the socket.
  • sendServerFeaturesCommand: Sends the server.features command to the proxy server.
  • close: Closes the connection to the Tor proxy.

Usage:

// Instantiate a socks socket at localhost and on the port selected by the
// tor service.
var socksSocket = await SOCKSSocket.create(
 proxyHost: InternetAddress.loopbackIPv4.address,
 proxyPort: tor.port,
 // sslEnabled: true, // For SSL connections.
 );

// Connect to the socks instantiated above.
await socksSocket.connect();

// Connect to bitcoincash.stackwallet.com on port 50001 via socks socket.
await socksSocket.connectTo(
'bitcoincash.stackwallet.com', 50001);

// Send a server features command to the connected socket, see method for
// more specific usage example..
await socksSocket.sendServerFeaturesCommand();
await socksSocket.close();

See also:

Constructors

SOCKSSocket({required String proxyHost, required int proxyPort, required bool sslEnabled})
Constructor.

Properties

hashCode int
The hash code for this object.
no setterinherited
proxyHost String
The host of the SOCKS5 proxy server.
final
proxyPort int
The port of the SOCKS5 proxy server.
final
responseController StreamController<List<int>>
Getter for the StreamController that listens to the _socksSocket and broadcasts, or the _secureSocksSocket and broadcasts if SSL is enabled.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
socket Socket
Getter for the underlying Socket that connects to the SOCKS5 proxy server.
no setter
sslEnabled bool
Is SSL enabled?
final
subscription StreamSubscription<List<int>>?
Getter for the StreamSubscription that listens to the _socksSocket or the _secureSocksSocket if SSL is enabled.
no setter

Methods

close() Future<void>
Closes the connection to the Tor proxy.
connect() Future<void>
Connects to the SOCKS socket.
connectTo(String domain, int port) Future<void>
Connects to the specified domain and port through the SOCKS socket.
listen(void onData(List<int> data)?, {Function? onError, void onDone()?, bool? cancelOnError}) StreamSubscription<List<int>>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sendServerFeaturesCommand() Future<void>
Sends the server.features command to the proxy server.
toString() String
A string representation of this object.
inherited
write(Object? object) → void
Converts object to a String by invoking Object.toString and sends the encoding of the result to the socket.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

create({required String proxyHost, required int proxyPort, bool sslEnabled = false}) Future<SOCKSSocket>
Creates a SOCKS5 socket to the specified proxyHost and proxyPort.