示例#1
0
        public void SendAsync(byte[] data, Action completed = null)
        {
#if UNITY_EDITOR
            _socket.SendAsync(data, () =>
            {
                UnityWebSocketDebuger.Send(this, data);
                if (completed != null)
                {
                    lock (sendCallbackQueue)
                    {
                        sendCallbackQueue.Enqueue(completed);
                    }
                }
            });
#else
            if (completed != null)
            {
                _socket.SendAsync(data, () =>
                {
                    lock (sendCallbackQueue)
                    {
                        sendCallbackQueue.Enqueue(completed);
                    }
                });
            }
            else
            {
                _socket.SendAsync(data);
            }
#endif
        }
示例#2
0
        public WebSocket()
        {
            _socket = new Uniform.WebSocket();

            _socket.OnOpen += (o, e) =>
            {
                lock (eventArgsQueue) { eventArgsQueue.Enqueue(e); }
            };
            _socket.OnClose += (o, e) =>
            {
                lock (eventArgsQueue) { eventArgsQueue.Enqueue(e); }
            };
            _socket.OnError += (o, e) =>
            {
                lock (eventArgsQueue) { eventArgsQueue.Enqueue(e); }
            };
            _socket.OnMessage += (o, e) =>
            {
                lock (eventArgsQueue) { eventArgsQueue.Enqueue(e); }
            };

            UnityWebSocketManager.Instance.Add(this);

#if UNITY_EDITOR
            UnityWebSocketDebuger.Create(this);
#endif
        }