Beispiel #1
0
 public TcpListener(Uri uri, SocketTransportSettings settings, ILoggerFactory loggerFactory)
 {
     _uri            = uri;
     _socketSettings = settings;
     _loggerFactory  = loggerFactory;
     _logger         = _loggerFactory.CreateLogger(nameof(TcpListener));
 }
Beispiel #2
0
        public SocketTransport(Socket socket, SocketTransportSettings settings, ILoggerFactory loggerFactory)
            : base(settings, ConnectionSide.Server, loggerFactory.CreateLogger(nameof(SocketTransport)))
        {
            var transport = CreateTransport(socket, settings.SecuritySettings);

            _channel = CreateChannel(transport, settings);
        }
Beispiel #3
0
        public SocketTransport(Uri uri, SocketTransportSettings settings, ILoggerFactory loggerFactory)
            : base(settings, ConnectionSide.Client, loggerFactory.CreateLogger(nameof(SocketTransport)))
        {
            var ip     = SocketTools.GetIP(uri, settings.IPVersion);
            var port   = uri.Port;
            var family = ip.AddressFamily;
            var socket = new Socket(family, System.Net.Sockets.SocketType.Stream, ProtocolType.Tcp);

            if (family == AddressFamily.InterNetworkV6)
            {
                socket.DualMode = true;
            }
            socket.SendBufferSize    = settings.SendBufferSize;
            socket.ReceiveBufferSize = settings.ReceiveBufferSize;

            socket.NoDelay = true;

            var transport = CreateTransport(socket, ip, port, settings.SecuritySettings);

            _channel = CreateChannel(transport, settings);
        }
Beispiel #4
0
        IMessageChannel CreateChannel(ITransportChannel transportChannel, SocketTransportSettings settings)
        {
            var framingProtocol = settings.FramingProtocol;

            switch (framingProtocol)
            {
            case FramingProtocol.SerialFragments:
            {
                return(new SerialMessageStreamChannel(transportChannel, settings));
            }

            case FramingProtocol.ConcurrentFragments:
            {
                return(new ConcurrentMessageStreamChannel(transportChannel, settings));
            }

            case FramingProtocol.UnorderedConcurrentFragments:
            {
                return(new UnorderedConcurrentMessageChannel(transportChannel, settings));
            }

            default: throw new NotSupportedException(framingProtocol.ToString());
            }
        }