private void OnReceiveDataChange(ReceiveDataEventArgs e)
        {
            EventHandler <ReceiveDataEventArgs> handler = ReceiveDataChange;

            if (handler != null)
            {
                handler(this, e);
            }
        }
        private int ClientReceiveCallBack(byte[] data, uint length, WebSocketClient.WEBSOCKET_PACKET_TYPES opCode, WebSocketClient.WEBSOCKET_RESULT_CODES resultCode)
        {
            try
            {
                if (opCode == WebSocketClient.WEBSOCKET_PACKET_TYPES.LWS_WS_OPCODE_07__CLOSE)
                {
                    _client.DisconnectAsync(this);

                    return(0);
                }
                else if (resultCode == WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_SUCCESS)
                {
                    var sData = Encoding.ASCII.GetString(data, 0, data.Length);

                    ReceiveDataEventArgs e = new ReceiveDataEventArgs();
                    e.ID   = ID;
                    e.Data = sData;

                    OnReceiveDataChange(e);

                    if (onDataReceived != null)
                    {
                        onDataReceived(sData);
                    }

                    return(1);
                }
                else if (resultCode == WebSocketClient.WEBSOCKET_RESULT_CODES.WEBSOCKET_CLIENT_INVALID_HANDLE)
                {
                    _client.DisconnectAsync(this);

                    return(0);
                }
                else
                {
                    return(0);
                }
            }
            catch (SocketException se)
            {
                if (debugMode)
                {
                    ErrorLog.Exception(string.Format("WebSocketCleint ID {0} SocketException Occured in ClientReceiveCallBack", ID), se);
                }

                return(0);
            }
            catch (Exception e)
            {
                if (debugMode)
                {
                    ErrorLog.Exception(string.Format("WebSocketCleint ID {0} Exception Occured in ClientReceiveCallBack", ID), e);
                }

                return(0);
            }
            finally
            {
                if (_client.Connected)
                {
                    _client.ReceiveAsync();
                }
            }
        }