Exemple #1
0
        public async Task Connect(Uri peer)
        {
            _clientWebSocket = (ClientWebSocketConnection)await WebSocketClient.Connect(peer, _log);

            _clientWebSocket.OnMessage = message => OnInvokeMessage(message);
            _clientDiscountWebSocket   = (ClientWebSocketConnection)await WebSocketClient.Connect(peer, _log, true);

            _clientDiscountWebSocket.OnMessage = message => OnInvokeMessage(message);
        }
Exemple #2
0
        public static async Task <WebSocketConnection> Connect(Uri peer, Action <string> log, bool messageLoop = false)
        {
            ClientWebSocket clientWebSocket = new ClientWebSocket();
            await clientWebSocket.ConnectAsync(peer, CancellationToken.None);

            switch (clientWebSocket.State)
            {
            case WebSocketState.Open:
                log($"Opening WebSocket connection to remote server {peer}");
                WebSocketConnection socket = new ClientWebSocketConnection(clientWebSocket, peer, log, messageLoop);
                return(socket);

            default:
                log?.Invoke($"Cannot connect to remote node status {clientWebSocket.State}");
                throw new WebSocketException($"Cannot connect to remote node status {clientWebSocket.State}");
            }
        }