@echo off REM FRP Client Startup Script (with auto-reconnection mechanism) REM When frpc exits due to network fluctuations or other reasons, it will automatically restart
setlocal enabledelayedexpansion
REM Get script directory set "SCRIPT_DIR=%~dp0" set "FRPC_BIN=%SCRIPT_DIR%frpc.exe" set "FRPC_CONFIG=%SCRIPT_DIR%frpc.toml" set "RESTART_DELAY=5"
REM Check if frpc.exe exists if not exist "%FRPC_BIN%" ( echo Error: frpc.exe file not found: %FRPC_BIN% pause exit /b 1 )
REM Check if config file exists if not exist "%FRPC_CONFIG%" ( echo Error: Config file not found: %FRPC_CONFIG% pause exit /b 1 )
REM Check if frpc is already running tasklist /FI "IMAGENAME eq frpc.exe" 2>NUL | find /I /N "frpc.exe">NUL if "%ERRORLEVEL%"=="0" ( echo Warning: Detected frpc.exe is already running, please stop it first using stop_frpc.bat pause exit /b 1 )
REM Display startup information set "CURRENT_TIME=%DATE% %TIME%" echo [%CURRENT_TIME%] Starting frpc (Attempt %RESTART_COUNT%)...
REM Run frpc cd /d "%SCRIPT_DIR%" "%FRPC_BIN%" -c "%FRPC_CONFIG%" set "EXIT_CODE=%ERRORLEVEL%"
REM Display exit information set "CURRENT_TIME=%DATE% %TIME%" echo [%CURRENT_TIME%] frpc exited with code: %EXIT_CODE%
REM If user presses Ctrl+C, exit code may be 0 or non-zero, but mainly check if interrupted REM We always try to restart here (unless user stops manually)
REM Wait for specified time before restarting echo [%CURRENT_TIME%] Auto-restarting in %RESTART_DELAY% seconds... timeout /t %RESTART_DELAY% /nobreak >nul
REM Check if should continue (can add conditional checks here) REM If user wants to stop, should use stop_frpc.bat