You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2022/09/14 10:05:43 UTC
[plc4x] branch develop updated: fix(plc-simulator): added -public option to listen on all addresses
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 3e82df23c fix(plc-simulator): added -public option to listen on all addresses
3e82df23c is described below
commit 3e82df23c5c2591717903d8f4e9a98d6d9837ffa
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Wed Sep 14 12:05:26 2022 +0200
fix(plc-simulator): added -public option to listen on all addresses
---
.../main/java/org/apache/plc4x/simulator/PlcSimulator.java | 5 +++++
.../apache/plc4x/simulator/server/cbus/CBusServerModule.java | 11 ++++++++++-
.../org/apache/plc4x/simulator/server/s7/S7ServerModule.java | 7 ++++++-
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/PlcSimulator.java b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/PlcSimulator.java
index d66d59da6..770a8ae49 100644
--- a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/PlcSimulator.java
+++ b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/PlcSimulator.java
@@ -146,6 +146,7 @@ public class PlcSimulator {
// Build options
Options options = new Options();
+ options.addOption("public", false, "listen on all interfaces (overrides host option)");
options.addOption("host", true, "display current time");
options.addOption("s7port", true, "changes the s7 port");
@@ -155,6 +156,10 @@ public class PlcSimulator {
// Map options
config.host = cmd.getOptionValue("host", "localhost");
+ if (cmd.hasOption("public")) {
+ LOGGER.info("Listening on all interfaces. (omitting {})", config.host);
+ config.host = null;
+ }
config.s7Port = cmd.getOptionValue("s7port");
return config;
diff --git a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/CBusServerModule.java b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/CBusServerModule.java
index 088ab4d41..78c837950 100644
--- a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/CBusServerModule.java
+++ b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/cbus/CBusServerModule.java
@@ -89,7 +89,16 @@ public class CBusServerModule implements ServerModule {
}).option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);
- bootstrap.bind(config.getHost(), CBusConstants.CBUSTCPDEFAULTPORT).sync();
+ int port = CBusConstants.CBUSTCPDEFAULTPORT;
+ if (config.getS7Port() != null) {
+ port = Integer.parseInt(config.getS7Port());
+ }
+ String host = config.getHost();
+ if (host != null) {
+ bootstrap.bind(host, port).sync();
+ } else {
+ bootstrap.bind(port).sync();
+ }
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new SimulatorException(e);
diff --git a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java
index f3bdacf3f..e14b5ffdb 100644
--- a/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java
+++ b/plc4j/utils/plc-simulator/src/main/java/org/apache/plc4x/simulator/server/s7/S7ServerModule.java
@@ -91,7 +91,12 @@ public class S7ServerModule implements ServerModule {
if (config.getS7Port() != null) {
port = Integer.parseInt(config.getS7Port());
}
- bootstrap.bind(config.getHost(), port).sync();
+ String host = config.getHost();
+ if (host != null) {
+ bootstrap.bind(host, port).sync();
+ } else {
+ bootstrap.bind(port).sync();
+ }
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new SimulatorException(e);