$ ./cmd/socks5/socks5
[socks5] 2023/11/29 17:40:38 listen tcp :1080: bind: address already in use
#!/usr/bin/env bash
set -e
netstat_out="$(netstat -nap 2>/dev/null | grep -w 1080 || true)"
if [ -n "$netstat_out" ]; then
echo "error: address already in use"
echo "$netstat_out"
if true; then
exit 1
else
echo "killing worker procs using port 1080"
netstat -nap 2>/dev/null | grep -w 1080 | awk '{ print $7 }' | cut -d/ -f1 | xargs kill
fi
fi
cd cmd/socks5/ &&
go build &&
cd ../.. &&
./cmd/socks5/socks5 &
socks5_pid=$!;
echo socks5_pid: $socks5_pid;
sleep 1;
curl --proxy socks5h://localhost:1080 https://httpbin.org/ip;
kill $socks5_pid
$ ./run.sh
socks5_pid: 371297
{
"origin": "xxxxxxxxxxxxx"
}
$ ./run.sh
error: address already in use
tcp6 0 0 :::1080 :::* LISTEN 371359/./cmd/socks5
tcp6 0 0 ::1:60936 ::1:1080 TIME_WAIT -