Пример #1
0
        public async Task StartAsync <T>() where T : IWebSocketClientHandler
        {
            var handler = ConvertManager.GetDefaultObject <T>();

            if (!(handler is WebSocketClientHandler clientHandler))
            {
                throw new MateralWebSocketClientException("Handler类型必须派生于WebSocketClientHandler");
            }
            _clientHandler = clientHandler;
            await StartAsync();
        }
Пример #2
0
        public async Task StartAsync <T>() where T : IWebSocketClientHandler
        {
            if (!(Config is DotNettyClientConfig webSocketClientConfig))
            {
                throw new MateralWebSocketClientException("Config类型必须派生于DotNettyClientConfig");
            }
            WebSocketClientHandshaker webSocketClientHandshaker = WebSocketClientHandshakerFactory.NewHandshaker(webSocketClientConfig.UriBuilder.Uri, WebSocketVersion.V13, null, true, new DefaultHttpHeaders());
            var handler = ConvertManager.GetDefaultObject <T>(webSocketClientHandshaker);

            if (!(handler is DotNettyClientHandler clientHandler))
            {
                throw new MateralWebSocketClientException("Handler类型必须派生于DotNettyClientHandler");
            }
            _clientHandler = clientHandler;
            _clientHandler.SetClient(this);
            await StartAsync();
        }