Skip to content

Commit

Permalink
Check for conflicting port usage during start of instance
Browse files Browse the repository at this point in the history
  • Loading branch information
MyHomeMyData committed Sep 1, 2024
1 parent 309fb2f commit 7a92add
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ More to come. Stay tuned.
-->
### **WORK IN PROGRESS**
* (MyHomeMyData) Changed default port to 3100 to avoid conflict with camera adapter
* (MyHomeMyData) Check for conflicting port usage during start of instance (not working yet)
* (MyHomeMyData) Check for conflicting port usage during start of instance

### 0.0.3 (2024-08-25)
* (MyHomeMyData) Disabled sinon should interface
Expand Down
11 changes: 7 additions & 4 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Flexcharts extends utils.Adapter {
this.startWebServer();
}

startWebServer(adapter) {
async startWebServer(adapter) {
this.log.debug(`Starting web server on http://localhost:${this.config.port}/`);

// Tools to select MIME-type based on file extension
Expand Down Expand Up @@ -185,13 +185,16 @@ class Flexcharts extends utils.Adapter {
});

// Start server
try {
const check_port = await this.getPortAsync(Number(this.config.port)); // Returns next available port number
if (check_port == Number(this.config.port)) {
// Requested port is available
this.webServer.listen({port: this.config.port}, () => {
this.log.info(`Server started on localhost:${this.config.port}`);
this.setState('info.connection', true, true);
});
} catch (e) {
this.log.error(`Start of http server failed on localhost:${this.config.port} - err=${e.message}`);
} else {
// Error: Requested port is already in use.
this.log.error(`Start of http server failed on localhost:${this.config.port}. Port is already in use. Next available port is ${check_port}. Pls. change port in configuration of instance.`);
this.setState('info.connection', false, true);
}
}
Expand Down

0 comments on commit 7a92add

Please sign in to comment.