Exemplo n.º 1
0
        public void Send(string _text)
        {
            if (NetworkState != State.Connected)
            {
                return;
            }

            mInstance.SendAsync(_text, null);
        }
Exemplo n.º 2
0
        private void Start()
        {
            Connect();

            _webSocket.OnOpen    += (sender, args) => { Debug.Log("OnOpen"); };
            _webSocket.OnClose   += (sender, args) => { Debug.Log("OnClose"); };
            _webSocket.OnError   += (sender, args) => { Debug.Log(args.Message); };
            _webSocket.OnMessage += (sender, args) =>
            {
                {
                    _content.Add(args.Data);
                    Debug.Log(args.Data);
                }
            };

            inputText.onSubmit.AddListener(arg0 =>
            {
                if (!_webSocket.IsConnected || !_webSocket.IsAlive)
                {
                    Connect();
                }

                _webSocket.SendAsync(arg0, b =>
                {
                    if (b)
                    {
                        Debug.Log("send success");
                        _content.Add(arg0);
                    }
                });
            });
        }
Exemplo n.º 3
0
        private void SendHeartBeat(WebSocketSharp.WebSocket ws)
        {
            var package = new Package(MsgType.ClientHeart, "");
            var data    = package.Body;

            ws.SendAsync(data, null);
        }
Exemplo n.º 4
0
 public static void SendMessage(string msg, Action <bool> OnCompleted = null)
 {
     if (_ws.IsConnected)
     {
         _ws.SendAsync(msg, (success) => { OnCompleted?.Invoke(success); });
     }
 }
Exemplo n.º 5
0
        public static async Task SendStringAsync(this WebSocket ws, string str)
        {
            var finished = false;

            ws.SendAsync(str, b => finished = b);
            await Task.Run(() =>
            {
                while (!finished)
                {
                    Thread.Sleep(1);
                }
            }
                           );
        }
Exemplo n.º 6
0
        public async Task SendMessage(BaseMessage message)
        {
            _currentMessageId++;
            message.Id = _currentMessageId;
            string json = JsonConvert.SerializeObject(message);

            var taskSource = new TaskCompletionSource <bool>();

            _webSocket.SendAsync(json, sent =>
            {
                if (sent)
                {
                    taskSource.SetResult(true);
                }
                else
                {
                    taskSource.SetException(new Exception("Error occured while sending message"));
                }
            });

            await taskSource.Task;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Send message
 /// </summary>
 /// <param name="buffer"></param>
 public void Send(byte[] buffer)
 {
     socket.SendAsync(buffer, null);
 }
Exemplo n.º 8
0
 public override void Send(byte[] data)
 {
     _socket.SendAsync(data, null);
 }