public async Task<SocksResponseStatus> InitiateConnection(IPAddress address, int port) { if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort) throw new ArgumentOutOfRangeException(nameof(port), "Port number is invalid"); if (!await _connectedCompletion.Task) return SocksResponseStatus.GeneralFailure; var request = new Socks5ConnectionRequest(SocksCommand.Connect, address, port); var result = await InternalClient.SendSerializable(request); if (!result) // TODO: Error HANDLING throw new InvalidOperationException("Something went wrong when sending serialization"); var connectionResponse = await InternalClient.ReceiveSerializable<Socks5ConnectionResponse>(); return connectionResponse.Status; }
public async Task<SocksResponseStatus> InitiateConnection(string domain, int port = 80) { if (string.IsNullOrWhiteSpace(domain)) throw new ArgumentException("Domain cannot be null or whitespace.", nameof(domain)); if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort) throw new ArgumentOutOfRangeException(nameof(port), "Port number is invalid"); if (!await _connectedCompletion.Task) return SocksResponseStatus.GeneralFailure; var request = new Socks5ConnectionRequest(SocksCommand.Connect, domain, port); var result = await InternalClient.SendSerializable(request); if (!result) // TODO: Error HANDLING throw new InvalidOperationException("Something went wrong when sending serialization"); var connectionResponse = await InternalClient.ReceiveSerializable<Socks5ConnectionResponse>(); return connectionResponse.Status; }