This commit is contained in:
nguyentrungthat 2025-11-05 13:11:35 +07:00
parent 21cb42ebc0
commit a4163a1cb5
1 changed files with 8 additions and 1 deletions

View File

@ -411,6 +411,7 @@ export class WebSocketIo {
// Kết nối tới station qua Telnet / Socket // Kết nối tới station qua Telnet / Socket
const client = new net.Socket() const client = new net.Socket()
return new Promise<void>((resolve, reject) => { return new Promise<void>((resolve, reject) => {
client.setTimeout(5000)
client.connect(station.port, station.ip, async () => { client.connect(station.port, station.ip, async () => {
console.log( console.log(
`Connected to station ${station.name} (${station.ip}) to clear line ${clearLine}` `Connected to station ${station.name} (${station.ip}) to clear line ${clearLine}`
@ -432,11 +433,17 @@ export class WebSocketIo {
client.on('error', (err) => { client.on('error', (err) => {
console.error(`Error clearing line ${clearLine}:`, err) console.error(`Error clearing line ${clearLine}:`, err)
reject(err) resolve()
}) })
client.on('close', () => { client.on('close', () => {
console.log(`Station connection closed (line ${clearLine})`) console.log(`Station connection closed (line ${clearLine})`)
resolve()
})
client.on('timeout', () => {
console.log(`Station connection timeout (line ${clearLine})`)
client.destroy()
resolve()
}) })
}) })
} }