Can anyone give me an example for how to add Socks5/VLess connection in my react-native application?
I have an VPN application, with button “Connect” but can’t find any info about how to make connections in react-native.
My current const to make connections:
const connectVPN = async () => {
// If already connected, reset timer
if (isConnected) {
resetTimer();
return;
}
setConnecting(true);
// Retry logic up to maxAttempts
for (let i = 0; i < maxAttempts; i++) {
try {
const res = await fetch('http://localhost:8080/api/v1/credentials');
if (!res.ok) throw new Error("Failed to get credentials");
const data = await res.json();
const {username, password} = data;
const success = true;
if (success) {
setIsConnected(true);
setConnectionAttempts(0);
setConnecting(false);
resetTimer();
startTimer();
return;
} else {
throw new Error("VPN connect failed");
}
} catch (err) {
console.log(err);
setConnectionAttempts(i + 1);
}
}
setConnecting(false);
alert(t('error'));
};
After the credentials step I need to set connection to VPNServer using Socks5 or VLess protocols
New contributor
David is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.