private void OnMessage(byte[] data)
        {
            var packet = new Packet(this._connection, new MemoryStream(data));

            var logData = new { messageType = data[0] };
            this._logger.Log(LogLevel.Trace, LOGCATEGORY, string.Format("message with id {0} arrived", data[0]), logData);

            if (data[0] == (byte)MessageIDTypes.ID_CONNECTION_RESULT)
            {
                this.OnConnectionIdReceived(BitConverter.ToInt64(data, 1));
            }
            else
            {
                this.PacketReceived(packet);
            }
        }
        private void OnClose(bool clean)
        {
            var reason = clean ? "CLIENT_DISCONNECTED" : "CONNECTION_LOST";

            var connection = this._connection;
            if (connection != null)
            {
                var logData = new { clean };
                this._logger.Log(LogLevel.Trace, LOGCATEGORY, string.Format("{0} disconnected.", connection.Id), logData);

                this._connectionManager.CloseConnection(connection, reason);

                connection.RaiseConnectionClosed(reason);

                var action = this.ConnectionClosed;

                if (action != null)
                {
                    action(connection);
                }
            }

        }