Ejemplo n.º 1
0
        public OTcpClient(string host, int port, Action connectionStabilised = null, Evaluator evaluator = null)
        {
            Host = host;
            Port = port;
            ConnectionStabilised = connectionStabilised;

            if (evaluator == null)
            {
                _evaluator = new Evaluator();
            }

            _serverQueryInterfaceProxy = CreateProxy <IQueryInterface>();

            new Thread(() => {
                while (_isKeepConnection)
                {
                    ConnectServer();
                    _connSync.Wait();
                }
            })
            {
                IsBackground = true
            }.Start();

            // enqueue sybmbol table call
            _symbolTable = new SymbolTable(_serverQueryInterfaceProxy.GetIndexedSymbols());
        }
Ejemplo n.º 2
0
        public OPipeClient(string pipeName, Action connectionStabilised = null, Evaluator evaluator = null)
        {
            _pipeName            = pipeName;
            ConnectionStabilised = connectionStabilised;

            if (evaluator == null)
            {
                _evaluator = new Evaluator();
            }

            _serverQueryInterfaceProxy = CreateProxy <IQueryInterface>();

            new Thread(() => {
                while (_isKeepConnection)
                {
                    ConnectPipeServer();
                    _connSync.Wait();
                    Thread.Sleep(3000); // Wait when OS close pipe if a pipe server was closed
                }
            })
            {
                IsBackground = true
            }.Start();

            // enqueue sybmbol table call
            _symbolTable = new SymbolTable(_serverQueryInterfaceProxy.GetIndexedSymbols());
        }
Ejemplo n.º 3
0
        private void ConnectServer()
        {
            var ns = new NetStream(ConnectTcp());

            _transfering?.Dispose();
            _transfering = new Transfering(ns, ns, BufferSize);

            var isReconnected = false;

            _transfering.ConnectionStabilised = OnConnectionStabilised + new Action(() => {
                if (isReconnected)
                {
                    _symbolTable = new SymbolTable(_serverQueryInterfaceProxy.GetIndexedSymbols());
                }
                else
                {
                    isReconnected = true;
                }
            });

            _transfering.ConnectionError = ex => {
                lock (_transfering) {
                    // for single raction
                    _transfering.ConnectionError = null;

                    _sendSync.Lock();
                    Console.WriteLine($"Connection ERROR {ex.Message}");
                    OnConnectionError(ex);

                    _connSync.Pulse();
                }
            };

            _transfering.StartReceiver(data => OTcpServer.DataHandler(_evaluator, data, _symbolTable));

            _sendSync.Unlock();
        }