Example #1
0
        public bool Connect()
        {
            if (Connected)
            {
                return(true);
            }

            try
            {
                _control.Connect(_controlEndPoint);
                _data.Connect(_dataEndPoint);
                _blitter = new Blitter();
                _blitter.Start();
                _blitter.SegmentReady += BlitterOnSegmentReady;
            }
            catch (Exception e)
            {
                if (_control.Connected)
                {
                    _control.Disconnect(true);
                }
                throw e;
            }

            Connected = true;
            var id     = _createAndSendControlPayload(CommandEnum.Init);
            var result = _getRegularResponse(id);

            return(Connected = result >= 0);
        }
Example #2
0
        public int Disconnect()
        {
            if (!Connected)
            {
                return(-1);
            }

            var id     = _createAndSendControlPayload(CommandEnum.Close);
            var result = _getRegularResponse(id);

            _control.Disconnect(true);
            _data.Disconnect(true);
            Connected = false;

            _blitter.Stop();
            _blitter.Dispose();
            _blitter = null;

            return(result);
        }