Skip to content

Commit

Permalink
Added Port Availability Check and Free Port Finder Function
Browse files Browse the repository at this point in the history
Description: This PR introduces a mechanism to check whether a specific port is available and to recursively find a free port if needed. The isPortAvailable function checks if a port is already in use. If the port is occupied, the getFreePortWithCheck function will continue searching for an available port. This helps prevent port conflicts and ensures the application runs smoothly.
  • Loading branch information
erdncyz authored Sep 26, 2024
1 parent 4a9ea2e commit 10be92b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/device-managers/IOSDeviceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { flatten, isEmpty } from 'lodash';
import { utilities as IOSUtils } from 'appium-ios-device';
import { IDevice } from '../interfaces/IDevice';
import { IDeviceManager } from '../interfaces/IDeviceManager';
import { asyncForEach, getFreePort } from '../helpers';
import { asyncForEach, getFreePortWithCheck } from '../helpers';
import log from '../logger';
import os from 'os';
import path from 'path';
Expand Down Expand Up @@ -223,8 +223,8 @@ export default class IOSDeviceManager implements IDeviceManager {
} else {
host = `http://${pluginArgs.bindHostOrIp}:${hostPort}`;
}
const wdaLocalPort = await getFreePort();
const mjpegServerPort = await getFreePort();
const wdaLocalPort = await getFreePortWithCheck();
const mjpegServerPort = await getFreePortWithCheck();
const totalUtilizationTimeMilliSec = await getUtilizationTime(udid);
const [sdk, name] = await Promise.all([this.getOSVersion(udid), this.getDeviceName(udid)]);
const { ProductType } = await getDeviceInfo(udid);
Expand Down Expand Up @@ -296,8 +296,8 @@ export default class IOSDeviceManager implements IDeviceManager {
const deviceTypes = await list.devicetypes;
for await (const device of buildSimulators) {
const productModel = IOSDeviceManager.getProductModel(deviceTypes, device);
const wdaLocalPort = await getFreePort();
const mjpegServerPort = await getFreePort();
const wdaLocalPort = await getFreePortWithCheck();
const mjpegServerPort = await getFreePortWithCheck();
const totalUtilizationTimeMilliSec = await getUtilizationTime(device.udid);
const modelInfo = this.findKeyByValue(productModel) || { Width: '', Height: '' };
returnedSimulators.push(
Expand Down

0 comments on commit 10be92b

Please sign in to comment.