Inheritance: ChannelBase
        public IChannel Create(string address)
        {
            var type = Type;
            var connectEndPoint = ConnectEndPoint;
            var connectToken = ConnectToken;

            if (string.IsNullOrEmpty(address) == false)
            {
                var parts = address.Split('|'); // type|endpoint|{token}
                if (parts.Length < 2)
                    throw new ArgumentException(nameof(address));
                type = (ChannelType)Enum.Parse(typeof(ChannelType), parts[0], true);
                connectEndPoint = IPEndPointHelper.Parse(parts[1]);
                connectToken = parts.Length > 2 ? parts[2] : null;
            }

            switch (type)
            {
                case ChannelType.Tcp:
                    var tcpChannel = new TcpChannel(CreateChannelLogger(), connectEndPoint, connectToken, PacketSerializer);
                    InitializeChannel(tcpChannel);
                    return tcpChannel;

                case ChannelType.Udp:
                    var udpChannel = new UdpChannel(CreateChannelLogger(), connectEndPoint, connectToken, PacketSerializer, (NetPeerConfiguration)UdpConfig);
                    InitializeChannel(udpChannel);
                    return udpChannel;

                default:
                    throw new InvalidOperationException("Unknown TransportType");
            }
        }
Beispiel #2
0
        public IChannel Create(string address)
        {
            var type            = Type;
            var connectEndPoint = ConnectEndPoint;
            var connectToken    = ConnectToken;

            if (string.IsNullOrEmpty(address) == false)
            {
                var parts = address.Split('|'); // type|endpoint|{token}
                if (parts.Length < 2)
                {
                    throw new ArgumentException(nameof(address));
                }
                type            = (ChannelType)Enum.Parse(typeof(ChannelType), parts[0], true);
                connectEndPoint = IPEndPointHelper.Parse(parts[1]);
                connectToken    = parts.Length > 2 ? parts[2] : null;
            }

            switch (type)
            {
            case ChannelType.Tcp:
                var tcpChannel = new TcpChannel(CreateChannelLogger(), connectEndPoint, connectToken, PacketSerializer);
                InitializeChannel(tcpChannel);
                return(tcpChannel);

            case ChannelType.Udp:
                var udpChannel = new UdpChannel(CreateChannelLogger(), connectEndPoint, connectToken, PacketSerializer, (NetPeerConfiguration)UdpConfig);
                InitializeChannel(udpChannel);
                return(udpChannel);

            default:
                throw new InvalidOperationException("Unknown TransportType");
            }
        }