示例#1
0
        private void FileWatcher_Created(object sender, FileSystemEventArgs e)
        {
            var transportStream = new FileTransportStream(
                new DirectoryInfo(e.FullPath),
                new DirectoryInfo(Path.Combine(_rootDir.FullName, e.Name, _localPeerId.ToString())));

            AcceptConnectionHandler?.Invoke(new AcceptConnectionEventArgs(transportStream, () =>
            {
                _streams.Add(transportStream);
            }));
        }
        void AcceptConnection(TransportConnectionEventArgs e)
        {
            var stream = new TcpTransportStream(e.Client);

            // Notify application protocol
            bool accepted      = false;
            var  applicationEE = new AcceptConnectionEventArgs(stream, () =>
            {
                _logger.LogInformation($"Accepted connection from {stream.RemoteEndPoint}");

                accepted = true;
                _streams.Add(stream);
            });

            AcceptConnectionHandler?.Invoke(applicationEE);

            if (!accepted)
            {
                e.Client.Dispose();
            }
        }