Skip to content

Commit

Permalink
Leverage the single-connection feature of Server version 7.4.
Browse files Browse the repository at this point in the history
(cherry picked from commit 00fe30ee4d916ddcda61eea4a4f34699322b1028)
  • Loading branch information
dario-weswit committed Jul 18, 2023
1 parent 69f6394 commit b001ff6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ and the same should be added in the <metadata_provider> block.
This requires that a suitable keystore with a valid certificate is provided. See the configuration details in the [provided template](https://lightstreamer.com/docs/ls-server/latest/remote_adapter_robust_conf_template/adapters.xml).
NOTE: For your experiments, you can configure the adapters.xml to use the same JKS keystore "myserver.keystore" provided out of the box in the Lightstreamer distribution. Since this keystore contains an invalid certificate, remember to configure your local environment to "trust" it.
The sample Remote Server provided in the `Deployment_DotNet_Adapters` directory in `deploy.zip` is already predisposed for TLS connection on all ports. You can rerun the demo with the new configuration after modifying DotNetStockListDemoLauncher.bat to run a command like this:<BR/>
`dotnet TestAdapter.dll /host xxxxxxxx /tls /data_rrport 6661 /data_notifport 6662 /metadata_rrport 6663 max_bandwidth=40 max_frequency=3 buffer_size=30`<BR/>
`dotnet TestAdapter.dll /host xxxxxxxx /tls /data_rrport 6661 /metadata_rrport 6663 max_bandwidth=40 max_frequency=3 buffer_size=30`<BR/>
where the same hostname supported by the provided certificate must be supplied.

#### Add Authentication
Expand All @@ -99,7 +99,7 @@ and the same should be added in the <metadata_provider> block.

See the configuration details in the [provided template](https://lightstreamer.com/docs/ls-server/latest/remote_adapter_robust_conf_template/adapters.xml).
The sample Remote Server provided in the `Deployment_DotNet_Adapters` directory in `deploy.zip` is already predisposed for credential submission on both adapters. You can rerun the demo with the new configuration after modifying DotNetStockListDemoLauncher.bat to run a command like this:<BR/>
`dotnet TestAdapter.dll /host localhost /user user1 /password pwd1 /data_rrport 6661 /data_notifport 6662 /metadata_rrport 6663 max_bandwidth=40 max_frequency=3 buffer_size=30`<BR/>
`dotnet TestAdapter.dll /host localhost /user user1 /password pwd1 /data_rrport 6661 /metadata_rrport 6663 max_bandwidth=40 max_frequency=3 buffer_size=30`<BR/>

Authentication can (and should) be combined with TLS encryption.

Expand Down Expand Up @@ -145,5 +145,8 @@ To build your own version of the Remote Server, follow these steps:

## Lightstreamer Compatibility Notes

* Compatible with Lightstreamer SDK for .NET Standard Adapters version 1.15 and newer.
* For instructions compatible with Lightstreamer SDK for .NET Adapters version 1.11, please refer to [this tag](https://github.com/Lightstreamer/Lightstreamer-example-StockList-adapter-dotnet/releases/tag/for_standard_1.11).
* Compatible with Lightstreamer SDK for .NET Standard Adapters version 1.15 or newer and Lightstreamer Server version 7.4 or newer.
- For a version of this example compatible with Lightstreamer Server version since 7.0, please refer to [this tag](https://github.com/Lightstreamer/Lightstreamer-example-StockList-adapter-dotnet/tree/for_Lightstreamer_7.3).
- For instructions compatible with Lightstreamer SDK for .NET Standard Adapters version 1.12 to 1.14, please refer to [this tag](https://github.com/Lightstreamer/Lightstreamer-example-StockList-adapter-dotnet/releases/tree/for_Lightstreamer_7.3).
- For instructions compatible with Lightstreamer SDK for .NET Adapters version 1.11, please refer to [this tag](https://github.com/Lightstreamer/Lightstreamer-example-StockList-adapter-dotnet/releases/tag/for_standard_1.11).

48 changes: 11 additions & 37 deletions src/src_standalone_launcher/StandaloneLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class StandaloneLauncher
public const string ARG_TLS = "tls"; // will use lowercase
public const string ARG_METADATA_RR_PORT = "metadata_rrport";
public const string ARG_DATA_RR_PORT = "data_rrport";
public const string ARG_DATA_NOTIF_PORT = "data_notifport";
public const string ARG_USER = "user";
public const string ARG_PASSWORD = "password";
public const string ARG_NAME = "name";
Expand Down Expand Up @@ -55,7 +54,6 @@ public static void Main(string[] args)
bool isTls = false;
int rrPortMD = -1;
int rrPortD = -1;
int notifPortD = -1;
string username = null;
string password = null;
string name = null;
Expand Down Expand Up @@ -98,13 +96,6 @@ public static void Main(string[] args)

nLog.Debug("Found argument: '" + ARG_DATA_RR_PORT + "' with value: '" + rrPortD + "'");
}
else if (arg.Equals(ARG_DATA_NOTIF_PORT))
{
i++;
notifPortD = Int32.Parse(args[i]);

nLog.Debug("Found argument: '" + ARG_DATA_NOTIF_PORT + "' with value: '" + notifPortD + "'");
}
else if (arg.Equals(ARG_USER))
{
i++;
Expand Down Expand Up @@ -166,7 +157,7 @@ public static void Main(string[] args)
}
nLog.Debug("Remote Metadata Adapter initialized");

ServerStarter starter = new ServerStarter(host, isTls, rrPortMD, -1);
ServerStarter starter = new ServerStarter(host, isTls, rrPortMD);
starter.Launch(server);
}

Expand All @@ -183,7 +174,7 @@ public static void Main(string[] args)
}
nLog.Debug("Remote Data Adapter initialized");

ServerStarter starter = new ServerStarter(host, isTls, rrPortD, notifPortD);
ServerStarter starter = new ServerStarter(host, isTls, rrPortD);
starter.Launch(server);
}
}
Expand All @@ -201,24 +192,22 @@ private static void Help()
nLog.Fatal("Usage: DotNetStockListDemoLauncher");
nLog.Fatal(" [/name <name>]");
nLog.Fatal(" /host <address> [/tls]");
nLog.Fatal(" /metadata_rrport <port> /data_rrport <port> /data_notifport <port>");
nLog.Fatal(" /metadata_rrport <port> /data_rrport <port>");
nLog.Fatal(" [/user <username> /password <password>]");
nLog.Fatal(" [\"<param1>=<value1>\" ... \"<paramN>=<valueN>\"]");
nLog.Fatal("Where: <name> is the symbolic name for both the adapters (1)");
nLog.Fatal(" <address> is the host name or ip address of LS server (2)");
nLog.Fatal(" <port> is the tcp port number where LS proxy is listening on (3)");
nLog.Fatal(" /tls if indicated, initiates a TLS-encrypted communication (4)");
nLog.Fatal(" <username> is sent, along with <password>, to the LS proxy (4)");
nLog.Fatal(" <paramN> is the Nth metadata adapter parameter name (5)");
nLog.Fatal(" <valueN> is the value of the Nth metadata adapter parameter (5)");
nLog.Fatal(" <port> is a tcp port number where LS proxy is listening on");
nLog.Fatal(" /tls if indicated, initiates a TLS-encrypted communication (3)");
nLog.Fatal(" <username> is sent, along with <password>, to the LS proxy (3)");
nLog.Fatal(" <paramN> is the Nth metadata adapter parameter name (4)");
nLog.Fatal(" <valueN> is the value of the Nth metadata adapter parameter (4)");
nLog.Fatal("Notes: (1) The adapter name is optional, if it is not given the adapter will be");
nLog.Fatal(" assigned a progressive number name like \"#1\", \"#2\" and so on");
nLog.Fatal(" (2) The communication will be from here to LS, not viceversa");
nLog.Fatal(" (3) The notification port is necessary for a Data Adapter, while it is");
nLog.Fatal(" not needed for a Metadata Adapter");
nLog.Fatal(" (4) TLS communication and user-password submission may or may not be needed");
nLog.Fatal(" (3) TLS communication and user-password submission may or may not be needed");
nLog.Fatal(" depending on the LS Proxy Adapter configuration");
nLog.Fatal(" (5) The parameters name/value pairs will be passed to the LiteralBasedProvider");
nLog.Fatal(" (4) The parameters name/value pairs will be passed to the LiteralBasedProvider");
nLog.Fatal(" Metadata Adapter as a Hashtable in the \"parameters\" Init() argument");
nLog.Fatal(" The StockListDemo Data Adapter requires no parameters");
nLog.Fatal("Aborting...");
Expand All @@ -237,14 +226,12 @@ public class ServerStarter : IExceptionHandler
private string _host;
private bool _isTls;
private int _rrPort;
private int _notifPort;

public ServerStarter(string host, bool isTls, int rrPort, int notifPort)
public ServerStarter(string host, bool isTls, int rrPort)
{
_host = host;
_isTls = isTls;
_rrPort = rrPort;
_notifPort = notifPort;
}

public void Launch(Server server)
Expand All @@ -259,7 +246,6 @@ public void Launch(Server server)
public void Run()
{
TcpClient _rrSocket = null;
TcpClient _notifSocket = null;

do
{
Expand All @@ -268,19 +254,13 @@ public void Run()
try
{
_rrSocket = CreateSocket(_host, _isTls, _rrPort);
if (_notifPort >= 0)
{
_notifSocket = CreateSocket(_host, _isTls, _notifPort);
}

nLog.Info("Connected");

break;
}
catch (SocketException)
{
nLog.Info("Connection failed, retrying in 10 seconds...");

Thread.Sleep(10000);
}

Expand All @@ -291,12 +271,6 @@ public void Run()
Stream _rrStream = GetProperStream(_rrSocket, _rrPort);
_server.RequestStream = _rrStream;
_server.ReplyStream = _rrStream;

if (_notifSocket != null)
{
Stream _notifStream = GetProperStream(_notifSocket, _notifPort);
_server.NotifyStream = _notifStream;
}
}
catch (AuthenticationException e)
{
Expand Down

0 comments on commit b001ff6

Please sign in to comment.