Esempio n. 1
0
        private void WebSocket_OnMessage(object sender, WebSocketSharp.MessageEventArgs messageEventArgs)
        {
            var eventArgs = new JsonEventArgs(messageEventArgs.Data);

            JsonRead?.Invoke(this, eventArgs);
            WebsocketPacketHandler.HandlePacket(messageEventArgs.Data);
        }
 void connection_JsonRead(object sender, JsonEventArgs e)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         JsonConsoleTextBox.AppendText($"IN\n{e.JsonData}\n\n");
         JsonConsoleTextBox.ScrollToEnd();
     });
 }
Esempio n. 3
0
        /// <summary>
        /// Sends a free-form, unsafe packet in JSON format.
        /// </summary>
        /// <param name="json">JSON packet string to be sent.</param>
        /// <remarks>Make sure the packet is WELL formed. Otherwise client will certainly get disconnected.</remarks>
        public void SendJson(string json)
        {
            if (IsReady && IsOpen)
            {
                WebSocket.Send(json);
            }

            var eventArgs = new JsonEventArgs(json);

            JsonWrite?.Invoke(this, eventArgs);
        }
Esempio n. 4
0
        /// <summary>
        /// Sends a predefined, tested and safe packet.
        /// </summary>
        /// <param name="packet">Packet to be sent.</param>
        public void SendPacket(Packet packet)
        {
            if (IsReady && IsOpen)
            {
                WebSocket.Send(packet);
            }

            var eventArgs = new JsonEventArgs(packet);

            JsonWrite?.Invoke(this, eventArgs);
        }