Changing TCPUtils to use SocketAsyncEventArgs instead of TAP functions, simple client<->server works with echoing messages

This commit is contained in:
Taha Afzal committed 2023-12-20 11:32:53 -05:00
1 parent cdc7da8c59
commit 1ceea4af5a
7 files changed
+217 -305

No files matched your search

@@ -6,16 +6,14 @@ using Bts.DataStreamExpressions;
using System.Collections.Generic;
using BCG;
using System.Threading;
bts.Log.Gen.info($"Starting DSPublisher");
Console.WriteLine("Starting DSPublisher...");
static void init(string[] args)
{
Console.WriteLine("Hit key to continue");
Console.ReadLine();
Func<string, string, Task> login = async (l, p) =>
{
bool run_echo_tcp_client_only = true;
static void init(string[] args) {
Func<string, string, Task> login = async (l, p) => {
var login = l;
var passwd = p;
var service_ctx = bts.api.core.ServiceContext.create();
@@ -25,29 +23,32 @@ static void init(string[] args)
Configuration.initialize();
Task.Run(async () => await login("bts", String.Empty));
}
init(args);
_publish_streams();
if (run_echo_tcp_client_only)
await start_echo_client();
else
_publish_streams();
static ViewStream build_stream(string stream_expression)
{
try
{
static ViewStream build_stream(string stream_expression) {
try {
var exp = DataStreamExpressionsInterpreter.Evaluate(stream_expression);
var rv = exp.getView(new Dictionary<string, StatementExpression>(0));
return rv;
}
catch (Exception ex)
{
} catch (Exception ex) {
bts.Log.assert(false, $"Could not build stream: {stream_expression} ex: {ex}");
return null;
}
}
async Task start_echo_client() {
Console.WriteLine("Starting DSPublisher in TCP client echo mode, Hit key to continue");
Console.ReadLine();
await SimpleTCPClientAsync.start("127.0.0.1", 12345);
Task.Delay(1000000000).Wait();
}
void _publish_streams()
{
void _publish_streams() {
PubTableBroker pb_broker = new PubTableBroker();
CloudStreamManager csm = new CloudStreamManager();
// get it from config
@@ -60,16 +61,14 @@ void _publish_streams()
{"literal_420","literal(\"x\", \"420.0\")"},
// {"bbo_ts","timeSeries(bbo())"}
};
foreach (var kv in streams_to_publish)
{
foreach (var kv in streams_to_publish) {
var name = kv.Key;
var exp = kv.Value;
BCG.ViewStream vs = build_stream(exp);
ViewPublisher vpub = new ViewPublisher(name, pb_broker, vs);
vs.onChange += on_change;
}
while (true)
{
while (true) {
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
ViewStreamDatabase.instance.doWork();
csm.doWork();
@@ -78,7 +77,6 @@ void _publish_streams()
void on_change(object obj)
{
void on_change(object obj) {
bts.Log.Gen.info($"DSPublisher on_change dp: {obj}");
}