Skip to content

Commit 6693b12

Browse files
Copilotromanettmarcschier
authored
Add reverse connect command line support to ConsoleReferenceServer (#3376)
* Add reverse connect command line parameter to ConsoleReferenceServer Co-authored-by: romanett <[email protected]> * Add reverse connect documentation for console server and client Co-authored-by: romanett <[email protected]> * Add error handling for invalid reverse connect URL Co-authored-by: romanett <[email protected]> * Resolve merge conflicts with master branch Co-authored-by: marcschier <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: romanett <[email protected]> Co-authored-by: marcschier <[email protected]> Co-authored-by: Marc Schier <[email protected]>
1 parent 0e8273e commit 6693b12

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed

Applications/ConsoleReferenceClient/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,34 @@ Some of these parameters are explained in more detail below.
77

88
To see all available parameters call console reference client with the parameter `-h`.
99

10+
## Reverse Connect
11+
12+
The OPC UA reverse connect feature allows an OPC UA server to initiate the connection to a client, rather than the traditional model where clients connect to servers. This is particularly useful in scenarios where the server is behind a firewall or NAT, making it difficult for clients to directly connect to it.
13+
14+
### How to use Reverse Connect
15+
16+
To enable reverse connect mode, specify the client endpoint URL using the `--rc` or `--reverseconnect` parameter:
17+
18+
```bash
19+
dotnet ConsoleReferenceClient.dll --rc=opc.tcp://localhost:65300 opc.tcp://localhost:62541/Quickstarts/ReferenceServer
20+
```
21+
22+
The client will start a reverse connect listener on the specified endpoint (e.g., `opc.tcp://localhost:65300`) and wait for the server to connect to it.
23+
24+
### Example: Client and Server with Reverse Connect
25+
26+
1. Start the client with reverse connect listener on port 65300:
27+
```bash
28+
dotnet ConsoleReferenceClient.dll --rc=opc.tcp://localhost:65300 opc.tcp://localhost:62541/Quickstarts/ReferenceServer
29+
```
30+
31+
2. In a separate terminal, start the server with reverse connect to the client:
32+
```bash
33+
dotnet ConsoleReferenceServer.dll --rc=opc.tcp://localhost:65300 -a
34+
```
35+
36+
The server will establish a reverse connection to the client endpoint, and the client will use this connection to communicate with the server.
37+
1038
### How to specify User Identity
1139
#### Username & Password
1240
Specify as console parameters:
@@ -18,3 +46,4 @@ Place your user certificate in the TrustedUserCertificatesStore (the path can be
1846
Specify console parameters:
1947
`-uc Thumbprint` (of the user certificate to select)
2048
`-ucp Password` (of the user certificates private key (optional))
49+

Applications/ConsoleReferenceServer/Program.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public static async Task<int> Main(string[] args)
7272
bool provisioningMode = false;
7373
char[] password = null;
7474
int timeout = -1;
75+
string reverseConnectUrlString = null;
7576

7677
string usage = Utils.IsRunningOnMono()
7778
? $"Usage: mono {applicationName}.exe [OPTIONS]"
@@ -98,6 +99,11 @@ public static async Task<int> Main(string[] args)
9899
"provision",
99100
"start server in provisioning mode with limited namespace for certificate provisioning",
100101
p => provisioningMode = p != null
102+
},
103+
{
104+
"rc|reverseconnect=",
105+
"Connect to the specified client endpoint for reverse connect. (e.g. rc=opc.tcp://localhost:65300)",
106+
url => reverseConnectUrlString = url
101107
}
102108
};
103109

@@ -185,6 +191,24 @@ await server
185191
logger.LogInformation("Start the server.");
186192
await server.StartAsync().ConfigureAwait(false);
187193

194+
// setup reverse connect if specified
195+
if (!string.IsNullOrEmpty(reverseConnectUrlString))
196+
{
197+
try
198+
{
199+
logger.LogInformation("Adding reverse connection to {Url}.", reverseConnectUrlString);
200+
var reverseConnectUrl = new Uri(reverseConnectUrlString);
201+
server.Server.AddReverseConnection(reverseConnectUrl);
202+
}
203+
catch (UriFormatException ex)
204+
{
205+
logger.LogError(ex, "Invalid reverse connect URL: {Url}", reverseConnectUrlString);
206+
throw new ErrorExitException(
207+
$"Invalid reverse connect URL: {reverseConnectUrlString}",
208+
ExitCode.ErrorInvalidCommandLine);
209+
}
210+
}
211+
188212
// Apply custom settings for CTT testing
189213
if (cttMode)
190214
{
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# OPC Foundation UA .NET Standard Reference Server
2+
3+
## Introduction
4+
5+
The console reference server can be configured using several console parameters.
6+
Some of these parameters are explained in more detail below.
7+
8+
To see all available parameters call console reference server with the parameter `-h`.
9+
10+
## Reverse Connect
11+
12+
The OPC UA reverse connect feature allows an OPC UA server to initiate the connection to a client, rather than the traditional model where clients connect to servers. This is particularly useful in scenarios where the server is behind a firewall or NAT, making it difficult for clients to directly connect to it.
13+
14+
### How to use Reverse Connect
15+
16+
To enable reverse connect mode, specify the client endpoint URL using the `--rc` or `--reverseconnect` parameter:
17+
18+
```bash
19+
dotnet ConsoleReferenceServer.dll --rc=opc.tcp://localhost:65300
20+
```
21+
22+
or
23+
24+
```bash
25+
dotnet ConsoleReferenceServer.dll --reverseconnect=opc.tcp://localhost:65300
26+
```
27+
28+
### Example: Server and Client with Reverse Connect
29+
30+
1. Start the client with reverse connect listener on port 65300:
31+
```bash
32+
dotnet ConsoleReferenceClient.dll --rc=opc.tcp://localhost:65300 opc.tcp://localhost:62541/Quickstarts/ReferenceServer
33+
```
34+
35+
2. In a separate terminal, start the server with reverse connect to the client:
36+
```bash
37+
dotnet ConsoleReferenceServer.dll --rc=opc.tcp://localhost:65300 -a
38+
```
39+
40+
The server will establish a reverse connection to the client endpoint, and the client will use this connection to communicate with the server.
41+
42+
### Additional Options
43+
44+
- `-a` or `--autoaccept`: Auto accept untrusted certificates (for testing only)
45+
- `-c` or `--console`: Log to console
46+
- `-l` or `--log`: Log app output
47+
- `-t` or `--timeout`: Timeout in seconds to exit application
48+
49+
For the complete list of options, use `--help`.

0 commit comments

Comments
 (0)