Exemplo n.º 1
0
        protected override async Task OnConnectAsync(CancellationToken cancellationToken)
        {
            _pipeClientIn =
                new NamedPipeClientStream(_remoteNamedPipeHost, _remoteNamedPipeName + "_OUT_FROM_SERVER",
                                          PipeDirection.In, PipeOptions.Asynchronous);

            _pipeClientOut =
                new NamedPipeClientStream(_remoteNamedPipeHost, _remoteNamedPipeName + "_IN_TO_SERVER",
                                          PipeDirection.Out, PipeOptions.Asynchronous);

            cancellationToken.ThrowIfCancellationRequested();

            if (State == ConnectionState.Connecting)
            {
                await _pipeClientOut.ConnectAsync(_clientConnectionSettings.ReconnectionDelayMilliseconds, cancellationToken);

                await _pipeClientIn.ConnectAsync(_clientConnectionSettings.ReconnectionDelayMilliseconds, cancellationToken);
            }
            else
            {
                await _pipeClientOut.ConnectAsync(cancellationToken);

                await _pipeClientIn.ConnectAsync(cancellationToken);
            }

            _connectedStream = new NamedPipeConnectedStream(
                $"{GetType()}",
                _remoteNamedPipeName + "_OUT_FROM_SERVER", _pipeClientIn,
                _remoteNamedPipeName + "_IN_TO_SERVER", _pipeClientOut);;
        }
Exemplo n.º 2
0
        protected override async Task OnConnectAsync(CancellationToken cancellationToken)
        {
            _pipeServerIn =
                new NamedPipeServerStream(
                    _localEndPointName + "_IN_TO_SERVER",
                    PipeDirection.In,
                    1,
                    PipeTransmissionMode.Byte,
                    PipeOptions.Asynchronous);

            _pipeServerOut =
                new NamedPipeServerStream(
                    _localEndPointName + "_OUT_FROM_SERVER",
                    PipeDirection.Out,
                    1,
                    PipeTransmissionMode.Byte,
                    PipeOptions.Asynchronous);

            if (State == ConnectionState.Connecting)
            {
                //when connecting accept connection with a timeout
                using var timeoutCancellationTokenSource =
                          new CancellationTokenSource(_serverConnectionSettings.ConnectionTimeoutMilliseconds);

                timeoutCancellationTokenSource.Token.Register(() =>
                {
                    _pipeServerIn.Close();
                    _pipeServerOut.Close();
                });

                await _pipeServerIn.WaitForConnectionAsync(cancellationToken);

                await _pipeServerOut.WaitForConnectionAsync(cancellationToken);
            }
            else // if (State == ConnectionState.LinkError)
            {
                await _pipeServerIn.WaitForConnectionAsync(cancellationToken);

                await _pipeServerOut.WaitForConnectionAsync(cancellationToken);
            }

            _connectedStream = new NamedPipeConnectedStream(
                $"{GetType()}",
                _localEndPointName + "_IN_TO_SERVER", _pipeServerIn,
                _localEndPointName + "_OUT_FROM_SERVER", _pipeServerOut);
        }
Exemplo n.º 3
0
        protected override Task OnConnectAsync(CancellationToken cancellationToken)
        {
            _connectedStream = new NamedPipeConnectedStream($"{GetType()}", "", _streamIn, "", _streamOut);

            return(Task.CompletedTask);
        }