void _websocket_MessageReceived(Windows.Networking.Sockets.MessageWebSocket sender, Windows.Networking.Sockets.MessageWebSocketMessageReceivedEventArgs args)
        {
            var ev = OnMessageReceived;

            if (ev != null)
            {
                try {
                    using (var reader = args.GetDataReader()) {
                        reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
                        var text = reader.ReadString(reader.UnconsumedBufferLength);
                        //System.Diagnostics.Debug.WriteLine(":: recived " + text);
                        Task.Factory.StartNew(() => ev(text));
                    }
                } catch {}
            }
        }
Exemple #2
0
 private void WebSocket_MessageReceived(Windows.Networking.Sockets.MessageWebSocket sender, Windows.Networking.Sockets.MessageWebSocketMessageReceivedEventArgs args)
 {
     try
     {
         using (DataReader dataReader = args.GetDataReader())
         {
             dataReader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
             string message = dataReader.ReadString(dataReader.UnconsumedBufferLength);
             Debug.WriteLine("Message received from MessageWebSocket: " + message);
             this.messageWebSocket.Dispose();
         }
     }
     catch (Exception ex)
     {
         Windows.Web.WebErrorStatus webErrorStatus = Windows.Networking.Sockets.WebSocketError.GetStatus(ex.GetBaseException().HResult);
         // Add additional code here to handle exceptions.
     }
 }