mirror of
https://github.com/pompurin404/mihomo-party.git
synced 2024-11-15 19:22:31 +08:00
fix find available port
This commit is contained in:
parent
dac2336eb6
commit
9f6aac708b
|
@ -24,7 +24,6 @@ function FindProxyForURL(url, host) {
|
||||||
export function findAvailablePort(startPort: number): Promise<number> {
|
export function findAvailablePort(startPort: number): Promise<number> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const server = net.createServer()
|
const server = net.createServer()
|
||||||
server.unref()
|
|
||||||
server.on('error', (err) => {
|
server.on('error', (err) => {
|
||||||
if (startPort <= 65535) {
|
if (startPort <= 65535) {
|
||||||
resolve(findAvailablePort(startPort + 1))
|
resolve(findAvailablePort(startPort + 1))
|
||||||
|
@ -32,13 +31,12 @@ export function findAvailablePort(startPort: number): Promise<number> {
|
||||||
reject(err)
|
reject(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
server.on('listening', () => {
|
||||||
server.listen(startPort, () => {
|
|
||||||
// 端口可用
|
|
||||||
server.close(() => {
|
server.close(() => {
|
||||||
resolve(startPort)
|
resolve(startPort)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
server.listen(startPort, '127.0.0.1')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user