Пример #1
0
        public void InvokeOnMessageBinary(byte[] data)
        {
            BwsMessage b = new BwsMessage
            {
                ID                  = GetNewIDFromLog(),
                Date                = DateTime.Now,
                Message             = Encoding.UTF8.GetString(data),
                MessageBinary       = data,
                MessageBinaryVisual = string.Join(", ", data),
                MessageType         = BwsMessageType.received,
                TransportType       = TransportType
            };

            if (DoLog)
            {
                Log.Add(b);

                if (Log.Count > LogMaxCount)
                {
                    Log.RemoveAt(0);
                }
            }


            OnMessage?.Invoke(b);
        }
Пример #2
0
        public void InvokeOnMessage(string par_message)
        {
            Console.WriteLine(par_message);

            BwsMessage b = new BwsMessage
            {
                ID            = GetNewIDFromLog(),
                Date          = DateTime.Now,
                Message       = par_message,
                MessageType   = BwsMessageType.received,
                TransportType = TransportType
            };



            if (DoLog)
            {
                Log.Add(b);

                if (Log.Count > LogMaxCount)
                {
                    Log.RemoveAt(0);
                }
            }


            OnMessage?.Invoke(b);
        }
Пример #3
0
        public void WsOnMessage(BwsMessage par_message)
        {
            par_message.ID = GetNewIDFromLog();
            log.Add(par_message);


            StateHasChanged();
        }
Пример #4
0
 private void WsOnMessage(BwsMessage par_message)
 {
     par_message.ID = GetNewIDFromLog();
     log.Add(par_message);
     if (log.Count > this.CountLog)
     {
         log.RemoveAt(0);
     }
     StateChanged();
 }
Пример #5
0
        public void WsSendMessage(string Ws_Message)
        {
            if (WebSocketHelper1.bwsState == BwsState.Open)
            {
                if (!string.IsNullOrEmpty(Ws_Message))
                {
                    switch (WebSocketHelper1.bwsTransportType)
                    {
                    case BwsTransportType.Text:
                        //log.Add(new BwsMessage()
                        //{
                        //    ID = GetNewIDFromLog(),
                        //    Date = DateTime.Now,
                        //    Message = Ws_Message,
                        //    MessageType = BwsMessageType.send,
                        //    TransportType = WebSocketHelper1.bwsTransportType,
                        //});
                        WebSocketHelper1.send(Ws_Message);
                        break;

                    case BwsTransportType.ArrayBuffer:
                        byte[]     data = Encoding.UTF8.GetBytes(Ws_Message);
                        BwsMessage b    = new BwsMessage()
                        {
                            ID            = GetNewIDFromLog(),
                            Date          = DateTime.Now,
                            Message       = Ws_Message,
                            MessageBinary = data,
                            MessageType   = BwsMessageType.send,
                            TransportType = WebSocketHelper1.bwsTransportType,
                        };
                        WebSocketHelper1.send(b.MessageBinary);
                        // b.MessageBinaryVisual = string.Join(", ", data);
                        //log.Add(b);
                        break;

                    case BwsTransportType.Blob:
                        break;

                    default:
                        break;
                    }
                    Ws_Message = string.Empty;
                }
            }
            else
            {
                Console.WriteLine("Connection is closed");
            }
        }
Пример #6
0
        public void WsSendMessage()
        {
            if (WebSocketHelper1.bwsState == BwsState.Open)
            {
                if (!string.IsNullOrEmpty(Ws_Message))
                {
                    switch (WebSocketHelper1.TransportType)
                    {
                    case BwsTransportType.Text:
                        log.Add(new BwsMessage()
                        {
                            ID            = GetNewIDFromLog(),
                            Date          = DateTime.Now,
                            Message       = Ws_Message,
                            MessageType   = BwsMessageType.send,
                            TransportType = WebSocketHelper1.TransportType,
                        });
                        WebSocketHelper1.Send(Ws_Message);
                        break;

                    case BwsTransportType.ArrayBuffer:

                        byte[]     data = Encoding.UTF8.GetBytes(Ws_Message);
                        BwsMessage b    = new BwsMessage()
                        {
                            ID            = GetNewIDFromLog(),
                            Date          = DateTime.Now,
                            Message       = Ws_Message,
                            MessageBinary = data,
                            MessageType   = BwsMessageType.send,
                            TransportType = WebSocketHelper1.TransportType,
                        };


                        WebSocketHelper1.Send(b.MessageBinary);

                        b.MessageBinaryVisual = string.Join(", ", data);

                        log.Add(b);

                        break;

                    case BwsTransportType.Blob:
                        break;

                    default:
                        break;
                    }

                    Ws_Message = string.Empty;
                }
                else
                {
                    BwsJsInterop.Alert("Please input message");
                }
            }
            else
            {
                BwsJsInterop.Alert("Connection is closed");
            }
        }