This commit is contained in:
lunaticbum 2026-03-27 18:03:06 +09:00
parent 62e408230e
commit d552584446
3 changed files with 66 additions and 6 deletions

View File

@ -1,7 +1,7 @@
object Defines {
val DETAILLOG = false
val LLM_PORT = 8080
val EMBEDDING_PORT = 8081
var LLM_PORT = 8080
var EMBEDDING_PORT = 8081
val AUTOSELL = false
val BLACKLISTEDSTOCKCODES = listOf<String>()
}

View File

@ -54,6 +54,7 @@ import service.TradingDecisionCallback
import ui.DashboardScreen
import ui.SettingsScreen
import ui.TradingDecisionLog
import util.PortFinder
// 화면 상태 정의
enum class AppScreen { Settings, Dashboard, TradingDecision }
@ -94,13 +95,21 @@ fun initLogger(isDebug: Boolean) {
println("🤫 운영 모드: 에러 로그만 출력합니다.")
}
}
private var isAppStarted = false
fun main() = application {
initLogger(DETAILLOG)
if (!isAppStarted) {
initLogger(DETAILLOG)
val (port1, port2) = PortFinder.findAvailablePortPair(18080)
println("🚀 AI 서버용 포트 할당 완료: 메인($port1), 서브($port2)")
LLM_PORT = port1
EMBEDDING_PORT = port2
isAppStarted = true
}
val trayState = rememberTrayState()
var isWindowOpen by remember { mutableStateOf(false) } // 창의 표시 상태 관리
LaunchedEffect(Unit) {
SystemSleepPreventer.start()
AutoTradingManager.startBackgroundScheduler()

View File

@ -0,0 +1,51 @@
package util
import java.net.ServerSocket
object PortFinder {
/**
* 사용 가능한 개의 포트를 찾아 Pair(첫번째, 두번째) 반환합니다.
* @param startPort 검색을 시작할 포트 번호
* @param mustBeConsecutive true일 경우 포트가 연속번호(ex: 18080, 18081)여야
*/
fun findAvailablePortPair(startPort: Int, mustBeConsecutive: Boolean = true): Pair<Int, Int> {
var currentPort = startPort
while (currentPort < 65534) {
if (isPortAvailable(currentPort)) {
if (mustBeConsecutive) {
// 연속된 포트가 필요한 경우 (n, n+1)
if (isPortAvailable(currentPort + 1)) {
return Pair(currentPort, currentPort + 1)
}
} else {
// 연속될 필요 없는 경우, 그다음 사용 가능한 포트를 찾음
val secondPort = findAvailablePort(currentPort + 1)
return Pair(currentPort, secondPort)
}
}
currentPort++
}
throw RuntimeException("⚠️ 사용 가능한 포트 쌍을 찾을 수 없습니다.")
}
/**
* 단일 포트 가용성 체크 (기존 로직 유지)
*/
fun findAvailablePort(startPort: Int): Int {
for (port in startPort..65535) {
if (isPortAvailable(port)) return port
}
throw RuntimeException("⚠️ 사용 가능한 포트가 없습니다.")
}
private fun isPortAvailable(port: Int): Boolean {
return try {
ServerSocket(port).use { socket ->
socket.reuseAddress = true
true
}
} catch (e: Exception) {
false
}
}
}